Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To retrieve specific elements from an array that is located within a custom data type in Postgres, you can use the ARRAY function with the indexing notation.

Assuming you have a custom data type called "mytype" that includes an array column called "myarray", here's an example query to retrieve the second element of the array for a specific row:

SELECT my_type.my_array[2] 
FROM my_table 
WHERE my_type.id = 123;

In this example, "mytable" is the table containing the custom data type, and "mytype.id" is the primary key for the row you want to retrieve. The indexing notation "[2]" specifies the second element of the array.

You can also use other array functions like ARRAY_LENGTH and UNNEST to retrieve more complex information from the array column.