Table lookup in Postgresql

From: Mehmet Yunt <mehmet(dot)yunt(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Table lookup in Postgresql
Date: 2013-03-22 20:16:43
Message-ID: CAAe8C7Tri4q29ESMjBytv0Fy=NzFiamMpVqXHvrb+NqaAMueHg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message David Johnston 2013-03-22 23:52:04 Re: Table lookup in Postgresql
Previous Message simonyanderson 2013-03-21 10:17:15 Re: How to Recover iPhone Contacts You Lost Somehow?