Matoe Matoe - 2 years ago 117
SQL Question

Multiple data types array in PostgreSQL

I'm sorry if this is a duplicate, although I couldn't find an exact answer for this anywhere:

Is there a way to create an array in postgreSQL which contains multiple data types?

I have an column of type

(array of type text); although I'd like to insert into this array three
entries and then a fourth entry, from type

Is there a way to do so? If so, how?

Answer Source

I don't believe there's a way to declare an array with multiple types; however, I think you can accomplish what you are trying to do with a composite type, e.g.,

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

You could then use this as the column type for your table or even declare a column of arrays of my_item[] if that fits your need.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download