Cannot select field from inherited table #3307
-
Environment
Description of issueI have these tables (note that two of them are inherited): CREATE TABLE "public"."countries" (
"code" text,
"name" text,
PRIMARY KEY ("code")
);
CREATE TABLE "public"."legal_persons" (
"id" uuid NOT NULL DEFAULT gen_random_uuid_v7(),
"name" text,
"country_code" text NOT NULL REFERENCES "public"."countries"(code),
PRIMARY KEY ("id")
);
CREATE TABLE "public"."entities" (
"entity_type_id" uuid
) INHERITS ("public"."legal_persons");
CREATE TABLE "public"."natural_persons" (
"born_at" date
) INHERITS ("public"."legal_persons"); I expected I could query
However, I see this error:
Is this simply not possible? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
This is a PostgreSQL thing. When you INHERIT a table, the FKs are not inherited at the same time - thus we can't detect any relationships. You'll need to add the same FK in the |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for the hint! |
Beta Was this translation helpful? Give feedback.
This is a PostgreSQL thing. When you INHERIT a table, the FKs are not inherited at the same time - thus we can't detect any relationships.
You'll need to add the same FK in the
entities
andnatural_persons
tables as well - not only for PostgREST, but also for your data validation.