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

Inheritance multi parent: more than one row returned by a subquery used as an expression #81

Open
deem0n opened this issue Dec 16, 2022 · 1 comment

Comments

@deem0n
Copy link

deem0n commented Dec 16, 2022

From the PG docs: A table can inherit from more than one parent table, in which case it has the union of the columns defined by the parent tables.

That means we can have many parents for one child table which make the concept of the PG table inheritance confusing ;-)

If we create table which have many parents, then we will have SQL error with schemainspect: more than one row returned by a subquery used as an expression

where child.oid = c.oid)

I would propose returning array of parent tables, but not sure if that is supported by the rest of the schemainspect

Here is the problematic SQL:

'"' || nmsp_parent.nspname || '"."' || parent.relname || '"' as parent

You can use

SELECT json_agg(
              '"' || nmsp_parent.nspname || '"."' || parent.relname || '"') as parent

or

SELECT array_agg(
              '"' || nmsp_parent.nspname || '"."' || parent.relname || '"') as parent

and probably even

SELECT array_agg( format('%I.%I', nmsp_parent.nspname, parent.relname)) as parent

But you may want to set quote_all_identifiers to ensure that all names are always quoted with ".

@rtrad89
Copy link

rtrad89 commented Jul 31, 2024

I added LIMIT 1 to line 43 to see if this improves the situation, and I am getting reasonable results - all inheritance I have is experimental, so I don't mind.

where child.oid = c.oid LIMIT 1)

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

2 participants