ts-postgres
ts-postgres copied to clipboard
ResultRow.get() returns null for user-defined enum types
Hi Guys,
So I have a few nums created (examples below), and a table that has fields with those enums as types. When I try to retrieve data using ResultRow.get() I get null values for these fields. Are these types supported at all, or should I get them in some specific way?
create type my_type as enum (
'unknown',
'source',
);
create type area as enum (
'left',
'right'
);
create table images (
id serial primary key,
url text,
type my_type,
area area
);
Here is my response for the database: (those null values are normal values in the database)
ResultRow {
names: [ 'id', 'url', 'type', 'area' ],
data: [
34,
'https://www.test.url/image.png',
null,
null
],
length: 4
}
Thanks!
I'll label this as an enhancement because it seems like enum types are simply not supported right now.
I also find an error happens if enum value is inserted with a placeholder:
Error: Unsupported data type: 16407
at addBinaryValue (/Users/kaede/umi/src/github.com/fairy-rockets/the-gear-of-seasons/server/node_modules/ts-postgres/src/protocol.ts:628:31)
at Writer.bind (/Users/kaede/umi/src/github.com/fairy-rockets/the-gear-of-seasons/server/node_modules/ts-postgres/src/protocol.ts:763:17)
at Client.bindAndExecute (/Users/kaede/umi/src/github.com/fairy-rockets/the-gear-of-seasons/server/node_modules/ts-postgres/src/client.ts:472:25)
at Client.receive (/Users/kaede/umi/src/github.com/fairy-rockets/the-gear-of-seasons/server/node_modules/ts-postgres/src/client.ts:740:34)
at Socket.<anonymous> (/Users/kaede/umi/src/github.com/fairy-rockets/the-gear-of-seasons/server/node_modules/ts-postgres/src/client.ts:245:35)
at Socket.emit (node:events:394:28)
at addChunk (node:internal/streams/readable:312:12)
at readableAddChunk (node:internal/streams/readable:287:9)
at Socket.Readable.push (node:internal/streams/readable:226:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
In the short-term (while we add support for enum types), you can cast the enum columns to text
or int
:
select <column-name>::text from <table>
@asjustis it's actually a little complicated to support these user object OIDs, i.e., types that are created using CREATE TYPE
. It requires pulling dynamic information from the pg_type
table.