You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Defining two enums with the same name under separate schemas in postgres produces runtime crashes upon inserts.
With schemas a and b and enum SOME_ENUM, the error is either "column \"that_enum\" is of type some_enum but expression is of type a.some_enum" or "column \"that_enum\" is of type some_enum but expression is of type b.some_enum" depending on the ordering of the rows returned here in fetch_type_id_by_name.
By joining pg_catalog.pg_type and pg_catalog.pg_namespace and filtering on current_schema(), it's possible to guide the selection at runtime via search_path. E.g. by changing the query in fetch_type_id_by_name to:
SELECTty.oidFROMpg_catalog.pg_type ty
JOINpg_catalog.pg_namespace ns
ONns.oid=ty.typnamespaceWHERE typname ILIKE $1ANDns.nspname= current_schema()
This seems brittle since current_schema() picks the first item on search_path which, to my understanding, means that types defined on public would not be found. Extending the query to accommodate the full search path would reintroduce the possibility of multiple returned matches, hence a way forward may be to pick the type based on precedence on the search_path.
Bug Description
Defining two enums with the same name under separate schemas in postgres produces runtime crashes upon inserts.
With schemas
a
andb
and enumSOME_ENUM
, the error is either"column \"that_enum\" is of type some_enum but expression is of type a.some_enum"
or"column \"that_enum\" is of type some_enum but expression is of type b.some_enum"
depending on the ordering of the rows returned here infetch_type_id_by_name
.Minimal Reproduction
A repro repo can be found here.
Info
rustc --version
: rustc 1.64.0 (a55dd71d5 2022-09-19)Attempted solution
By joining
pg_catalog.pg_type
andpg_catalog.pg_namespace
and filtering oncurrent_schema()
, it's possible to guide the selection at runtime viasearch_path
. E.g. by changing the query infetch_type_id_by_name
to:This seems brittle since
current_schema()
picks the first item onsearch_path
which, to my understanding, means that types defined onpublic
would not be found. Extending the query to accommodate the full search path would reintroduce the possibility of multiple returned matches, hence a way forward may be to pick the type based on precedence on thesearch_path
.Related issues
#1171
#1576
The text was updated successfully, but these errors were encountered: