From: | Raghavendra <raghavendra(dot)rao(at)enterprisedb(dot)com> |
---|---|
To: | Sameer Thakur <samthakur74(at)gmail(dot)com> |
Cc: | Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Populating array of composite datatype |
Date: | 2013-08-07 10:53:00 |
Message-ID: | CA+h6AhiaZSMrhbVXjy4gfi5SRfMHdh58Q3P=pqP=rVtwANyHig@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, Aug 7, 2013 at 4:04 PM, Sameer Thakur <samthakur74(at)gmail(dot)com> wrote:
> Hello,
> I have a composite datatype abc which has two integer fields x,y.
> I have a table Test which has an array of abc.
> I am trying to populate Test. Tried
> insert into test values (ARRAY[abc(1,2)]); but got error
> ERROR: function abc(integer, integer) does not exist
>
> Is there anyway for doing this?
>
>
I think you need to use row() and explicit type cast.
http://www.postgresql.org/docs/9.2/static/rowtypes.html
postgres=# create type abc as (x integer, y integer);
CREATE TYPE
postgres=# create table foo(val abc[]);
CREATE TABLE
postgres=# insert into foo values (array[row(1,2)::abc]);
INSERT 0 1
postgres=# insert into foo values (array[row('1','2')::abc]);
INSERT 0 1
postgres=# select * from foo ;
val
-----------
{"(1,2)"}
{"(1,2)"}
(2 rows)
---
Regards,
Raghavendra
EnterpriseDB Corporation
Blog: http://raghavt.blogspot.com/
From | Date | Subject | |
---|---|---|---|
Next Message | Chris Travers | 2013-08-07 10:56:34 | Re: Populating array of composite datatype |
Previous Message | BladeOfLight16 | 2013-08-07 10:38:28 | Re: Staging Database |