There is a table ( main_table ) with the following fields:
id , custom_type[]
custom_type was created like this:
CREATE TYPE custom_type AS (param1 integer, param2 integer);
There are two more tables, where param1 is the foreign key of the foreign_table_1 table, and param2 the foreign_table_2 table.
How to make it so that you can JOIN these two tables to the custom_type array? The resulting query should look something like this:
SELECT * FROM (SELECT custom_type FROM main_table WHERE id = 1) AS t LEFT JOIN foreign_table_1 ON t.param1 = foreign_table_1.id LEFT JOIN foreign_table_2 ON t.param2 = foreign_table_2.id My problem is that I can not translate an array into a table. That is, making a request like this:
SELECT t.param1 FROM (SELECT custom_type FROM main_table WHERE id = 1) AS t I get the error that the t.param1 column does not exist.
Maybe there is some other solution without using the composite type. The main thing for me in the main_table to store an array of keys param1 , param2 .