How to search for composite type array

From: ChoonSoo Park <luispark(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: How to search for composite type array
Date: 2012-10-01 21:49:44
Message-ID: CACgbiFtfrX5SGFEZSPDFpAOE=PtqA8UzJXDOF8Mq-n3HcnTgUA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello postgresql gurus,

I want to have an array of composite type in a table. Retrieving/saving
value work fine.

I just wonder how I can search against composite type array.

CREATE TYPE CompXYZ AS (
attr1 integer,
attr2 text,
attr3 inet
);

CREATE TABLE sample (
id integer not null primary key,
list CompXYZ[]
);

insert into sample values (1, '{"(1,abc,127.0.0.1)", "(5,def,10.0.1.2)"}');
insert into sample values (2, '{"(10,hello,127.0.0.1)",
"(20,def,10.0.1.2)"}');
insert into sample values (3, '{"(20,hello,10.1.1.1)",
"(30,there,10.1.1.2)"}');

How I can search a row containing "hello" for attr2?

I know if I have a separate table for saving 3 attributes along with
foreign key to sample table, then I can achieve my goal.
I just want to know if there is a way to do the same thing using composite
array.

Thank you,
Choon Park

Responses

Browse pgsql-general by date

  From Date Subject
Next Message yary 2012-10-01 22:02:09 Re: Pg, Netezza, and... Sybase?
Previous Message Alan Hodgson 2012-10-01 21:02:23 Re: Securing .pgpass File?