From: | rchowdhury <rchowdhury(at)alumni(dot)upenn(dot)edu> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Use for loop in stored procedure to join query results |
Date: | 2010-11-30 17:17:39 |
Message-ID: | 1291137459357-3286416.post@n5.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Hello,
I have a table similar to the following:
id probe value
1 asdf 10
1 qwer 20
1 zxcv 30
2 asdf 40
2 qwer 50
2 zxcv 60
I would like to create a stored procedure or function that will make a view
with the data as follows:
1 2
asdf 10 40
qwer 20 50
zxcv 30 60
Does anyone know how to do this? I am attempting to make a stored procedure
that...
1. SELECT all distinct "id"s
2. FOR LOOP to iterate over each "id", SELECT probe, value WHERE
id=<current id>
3. JOIN resulting table to table from previous iteration of the FOR loop
Unfortunately, I am not sure if this is a good way to do this. And I am not
familiar with stored procedure syntax. Can anyone help with this?
Thanks,
RC
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Use-for-loop-in-stored-procedure-to-join-query-results-tp3286416p3286416.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.
From | Date | Subject | |
---|---|---|---|
Next Message | Mick | 2010-11-30 17:33:58 | Attempting backup |
Previous Message | Stuart Kendrick | 2010-11-28 19:41:00 | Re: debugging SQL statements |