All we need is an easy explanation of the problem, so here it is.
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.
How to solve :
I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.
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?)
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂