Skip to content

Support enum types #17

@spencerwilson

Description

@spencerwilson

Use case: Our database has tables with some columns of enum types. We use enums as an alternative to text or similar in cases where the set of possible values is finite and relatively small. We do not need support for array-of-enum types. <- this gets you out of the business of having to support an interface where users tell the library what the machine-generated pg_enum.enumtypid OIDs for each enum type are.

It would be nice to be able to serialize JS values to their binary format for use in a copy-from operation. Encoding-wise it looks like enum variants ("labels") are case-sensitive strings, so a suitable JS encoding may be string. Looking at pg_enum and pg_type, it looks like enum variants all use enum_send and enum_recv for typsend and typrecv. Those, in turn, haven't changed between Postgres 12 and 13:

Looks like in terms of send and recv, the only information present on the wire is the label, which is just a string of length < NAMEDATALEN, which docs say

The length of an enum value's textual label is limited by the NAMEDATALEN setting compiled into PostgreSQL; in standard builds this means at most 63 bytes.

So perhaps this would be relatively straightforward to support? Might be very similar to text. My C++ isn't very strong so I'm unsure precisely what the code would look like in JS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions