Skip to content

Conversation

@saward
Copy link
Contributor

@saward saward commented May 10, 2022

When you have two schemas with the same table name in them, you get the following error:

Error: error querying table comments: pq: more than one row returned by a subquery used as an expression

This change fixes that so that the query only fetches comments for the table that belongs to the schema that's being queried.

There might be other places in gnorm where it makes a similar assumption that table names will be unique across schemas, but for my project this change fixed my error and produces the same output as it did before I added the schema with table name matching the name from the other schema.

@saward
Copy link
Contributor Author

saward commented Jun 27, 2023

Hi @natefinch, could you possibly review this and merge please?

@marcobeierer
Copy link

Hi @saward

I ran into the same issue today with three schema where tables with the same name existed in two schema.

I tried your PR, but it didn't solve the problem, had a closer look and found a solution. Shouldn't the subquery look like:

SELECT pg_catalog.col_description(c.oid, cols.ordinal_position::int)
FROM pg_catalog.pg_class c
    JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname = cols.table_name
    AND n.nspname = cols.table_schema

instead of:

SELECT pg_catalog.col_description(c.oid, cols.ordinal_position::int)
FROM pg_catalog.pg_class c
    JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname = cols.table_name
    AND n.nspname IN (%s)

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

Successfully merging this pull request may close these issues.

2 participants