Is it possible to define recursive composite types in Postgres 13?
create type "t" as ( "a" int, "b" t );
I am aware that I can use a table with a parent-child relationship. The only disadvantage is that I will need to query each nested level instead of directly accessing the nested data.
I am also aware that I can use
jsonb, but I am not sure if it can access the nested data directly without querying each nested level?
What are the other alternatives using PL/pgSQL only?
I need to access each nested level separately.
No, "recursive" type definitions are not possible in Postgres.
You cannot reference a type in
CREATE TYPE that is not registered, yet.
(What would terminate the recursion anyway?)
External links referenced by this document: