Table lookup in Postgresql - Mailing list pgsql-novice

From Mehmet Yunt
Subject Table lookup in Postgresql
Date
Msg-id CAAe8C7Tri4q29ESMjBytv0Fy=NzFiamMpVqXHvrb+NqaAMueHg@mail.gmail.com
Whole thread Raw
Responses Re: Table lookup in Postgresql
List pgsql-novice
Hi All

I have a table that contains arrays of integers.  These integers
are code names for quantities. Each quantity (hence integer) has also
an associated index in a bigger array.

For example

Row in Table A
{5,6,7,8,9}

Table B contains the look up for the indices

Val   Idx
5      10
6       1
7       9
8       2
9       3

What I would like to do is to create a row in table C for all rows in table A that contains a vector where the indices corresponding to the elements in the A table are 1 and the remainder are 0 like

{ 0,1, 1,0,0,1,0,0,1,1}

where the maximum length of this vector is known

How can I best do it in Postgresql? Should I loop using PL/PgSQL?

Thanks
Mehmet


 

pgsql-novice by date:

Previous
From: simonyanderson
Date:
Subject: Re: How to Recover iPhone Contacts You Lost Somehow?
Next
From: David Johnston
Date:
Subject: Re: Table lookup in Postgresql