-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Conversation
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 functionsarray_in
andarray_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)
There was a problem hiding this comment.
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, usepg_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.
Seeing as this would only work for Postgres < 8.3, I'm closing this PR for now and leaving the issue open. |
See #1353.