Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Enum arrays - see #1353. #1362

Closed
wants to merge 2 commits into from

Conversation

bwbroersma
Copy link

See #1353.

@@ -555,7 +557,7 @@ allColumns tabs =
JOIN pg_enum e ON t.oid = e.enumtypid
JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
GROUP BY s,n
) AS enum_info ON (info.udt_name = enum_info.n)
) AS enum_info ON (trim(leading '_' from info.udt_name) = enum_info.n)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Would like to see an example output of this, not sure why the trim leading is needed.

Copy link
Author

@bwbroersma bwbroersma Jul 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The udt_name (actually pg_type.typname pg_type docs) for enum arrays has one (or possible more?) leading _, see the CREATE TYPE docs:

Whenever a user-defined type is created, PostgreSQL automatically creates an associated array type, whose name consists of the element type's name prepended with an underscore, and truncated if necessary to keep it less than NAMEDATALEN bytes long. (If the name so generated collides with an existing type name, the process is repeated until a non-colliding name is found.) This implicitly-created array type is variable length and uses the built-in input and output functions array_in and array_out. The array type tracks any changes in its element type's owner or schema, and is dropped if the element type is.

But your comment about 'Example output' is right in another way at least for the Swagger UI: #1353 (comment)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok before Postgresql 8.3 this was a valid solution, but my solution is no longer valid, see the CREATE TYPE docs the Notes section:

Before PostgreSQL version 8.3, the name of a generated array type was always exactly the element type's name with one underscore character (_) prepended. (Type names were therefore restricted in length to one less character than other names.) While this is still usually the case, the array type name may vary from this in case of maximum-length names or collisions with user type names that begin with underscore. Writing code that depends on this convention is therefore deprecated. Instead, use pg_type.typarray to locate the array type associated with a given type.

It may be advisable to avoid using type and table names that begin with underscore. While the server will change generated array type names to avoid collisions with user-given names, there is still risk of confusion, particularly with old client software that may assume that type names beginning with underscores always represent arrays.

@bwbroersma bwbroersma changed the title Enum arrays - see #1353. WIP: Enum arrays - see #1353. Jul 25, 2019
@bwbroersma bwbroersma changed the title WIP: Enum arrays - see #1353. [WIP]: Enum arrays - see #1353. Jul 25, 2019
@bwbroersma bwbroersma changed the title [WIP]: Enum arrays - see #1353. [WIP] Enum arrays - see #1353. Jul 25, 2019
@wolfgangwalther wolfgangwalther changed the base branch from master to main December 31, 2020 14:12
@monacoremo
Copy link
Member

Seeing as this would only work for Postgres < 8.3, I'm closing this PR for now and leaving the issue open.

@monacoremo monacoremo closed this Apr 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants