| From: | Seb <spluque(at)gmail(dot)com> |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | referencing column aliases in select list |
| Date: | 2008-04-04 04:02:26 |
| Message-ID: | 874paiz2r1.fsf@patagonia.sebmags.homelinux.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Hi,
I have a SELECT statement that is a bit involved in terms of
calculations, so I wanted to set up some column aliases and refer to
them further down the select list:
---<---------------cut here---------------start-------------->---
SELECT table1.col1 - table2.col1 AS diff1,
table1.col2 + table2.col2 AS sum1,
sum1 - diff1
FROM table1 INNER JOIN table2 ON (table1.id = table2.id)
---<---------------cut here---------------end---------------->---
but this fails with the error message that sum1 column is not known.
How can one get around this? The calculations are quite involved and
would be difficult and error-prone to repeat them anywhere they're
needed in the select list. Thanks in advance for any pointers.
Cheers,
--
Seb
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Pavan Deolasee | 2008-04-04 04:31:31 | Re: [HACKERS] ANALYZE getting dead tuple count hopelessly wrong |
| Previous Message | Chris Velevitch | 2008-04-04 04:00:00 | Re: pg_dump ignoring without oids |