| From: | Zach Seaman <znseaman(at)gmail(dot)com> |
|---|---|
| To: | "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org> |
| Subject: | Insert output query to a column from a joined table in PostgreSQL 9.1 |
| Date: | 2013-02-14 03:35:10 |
| Message-ID: | CACVtUUt-3kMhD5AwpJR45HzpD9w+W3XoVzYbRuytLNuvUc01kA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-novice |
I'm fairly new to PostgreSQL 9.1 and would like to set each of `CASE WHEN`
clauses to new columns in table `s` after joining to table `t`.
This is my query:
`SELECT s.tipo, s.mod,
CASE WHEN s.tipo = 1 THEN t.bsolidokgd
WHEN s.tipo = 2 THEN t.osolidokgd
ELSE t.osolidokgd
END AS solidokgd,
CASE WHEN s.tipo = 1 THEN t.bbiolld
WHEN s.tipo = 2 THEN t.obiolld
ELSE t.obiolld
END AS biolld,
CASE WHEN s.tipo = 1 THEN t.bbiogasm3d
WHEN s.tipo = 2 THEN t.obiogasm3d
ELSE t.obiogasm3d
END AS biogasm3d
FROM bmc.sisinst s INNER JOIN bmc.temperadoest t ON s.mod = t.mod;`
Is there a way to `INSERT INTO` or `UPDATE` table `s` with a `CASE WHEN`
clause from table `t`?
Thanks again for all the help,
--
*Zach Seaman*
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Keith Ouellette | 2013-02-14 15:04:37 | Re: pgAgent and WAL streaming |
| Previous Message | Daniel Staal | 2013-02-14 03:23:48 | Re: pgAgent and WAL streaming |