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

postgresql - same user-defined-type present in multiple schema breaks the process #140

Open
LaksSwaminathan opened this issue Dec 7, 2021 · 3 comments

Comments

@LaksSwaminathan
Copy link

Folks,

I have a situation where the same user-defined-type name is re-used across two different schema in the same database, and it breaks the process.

i think the query that constructs the columns of a table needs a small tweak :

Line 32 on schema_inspector.rs needs to change from :

const TABLE_COLUMNS_QUERY: &str = "SELECT cc.column_name, cc.ordinal_position, cc.data_type, pt.oid
                                   FROM information_schema.columns as cc
                                   JOIN pg_catalog.pg_type as pt
                                   ON cc.udt_name = pt.typname
                                   WHERE cc.table_schema = $1 and cc.table_name = $2
                                   ORDER BY cc.ordinal_position ASC";

to

const TABLE_COLUMNS_QUERY: &str = "SELECT cc.column_name, cc.ordinal_position, cc.data_type, pt.oid
                                   FROM information_schema.columns as cc
                                   JOIN pg_catalog.pg_type as pt
                                   ON cc.udt_name = pt.typname
                                   LEFT JOIN pg_catalog.pg_namespace as pn
                                   ON (
                                        cc.data_type = 'USER-DEFINED'
                                        AND cc.table_schema = pn.nspname
                                        and pn.oid = pt.typnamespace
                                      )
                                   WHERE cc.table_schema = $1 and cc.table_name = $2
                                   AND ( cc.data_type <> 'USER-DEFINED' OR pn.nspname is not null )
                                   ORDER BY cc.ordinal_position ASC";

Mainly, it is ensuring that the schema name is used when finding the type of a column, when the type is user-defined.

@evgeniy-r
Copy link
Member

Hello!
I will take a look.

@mbeynon
Copy link
Contributor

mbeynon commented Feb 18, 2022

I think this is a dup of my later reported issue and subsequent PR:

#148
#149

Good news is may be fixed.

@evgeniy-r
Copy link
Member

Can you prepare a PR please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants