Array of data arrays in PostgreSQL

Sorry if this is a duplicate, although I could not find the exact answer for this anywhere:
Is there a way to create an array in postgreSQL that contains several data types?

I have a column of type text[] (an array of text of type); although I would like to insert three text entries into this array, and then a fourth entry, starting with type integer .

Is there any way to do this? If so, how?

+6
source share
1 answer

I do not believe that there is a way to declare an array with several types; however, I think you can accomplish what you are trying to do with a composite type , like

 create type my_item as ( field_1 text, field_2 text, field_3 text, field_4 number ); 

You can then use this as a column type for your table, or even declare a column of arrays my_item[] if it suits you.

+10
source

Source: https://habr.com/ru/post/901712/


All Articles