Re: Offtopic: psql

Lists: pgsql-sql
From: "Philippe Lang" <philippe(dot)lang(at)attiksystem(dot)ch>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Reuse previously calculated column in sql query?
Date: 2004-10-20 12:50:11
Message-ID: 6C0CF58A187DA5479245E0830AF84F42080442@poweredge.attiksystem.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Hello,

Is it possible to reuse a previously calculated column in a following
column, like:

SELECT
foo.val1 AS col1,
long_calculation(foo.val1) AS col2,
COL2 * 0.75 AS col3
FROM foo;

instead of writing:

SELECT
foo.val1 AS col1,
long_calculation(foo.val1) AS col2,
long_calculation(foo.val1) * 0.75 AS col3
FROM foo;

Philippe


From: Rod Taylor <pg(at)rbt(dot)ca>
To: Philippe Lang <philippe(dot)lang(at)attiksystem(dot)ch>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Reuse previously calculated column in sql query?
Date: 2004-10-20 13:05:38
Message-ID: 1098277537.747.91.camel@home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

On Wed, 2004-10-20 at 08:50, Philippe Lang wrote:
> Hello,
>
> Is it possible to reuse a previously calculated column in a following
> column, like:

SELECT col1
, col2
, col2 * 0.75 AS col3
FROM (SELECT foo.val1 AS col1
, long_calculation(foo.val1) AS col2
FROM foo) AS tab;


From: "Iain" <iain(at)mst(dot)co(dot)jp>
To: "Rod Taylor" <pg(at)rbt(dot)ca>, "Philippe Lang" <philippe(dot)lang(at)attiksystem(dot)ch>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Reuse previously calculated column in sql query?
Date: 2004-10-21 01:31:00
Message-ID: 008f01c4b70d$a22184a0$7201a8c0@mst1x5r347kymb
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Using the the sub-select is one way, but there is another way.

If the function can be declared as strict or immutable the you can call it
as many times as you like in a single transaction and it will only be
evaluated once. As far as I know this does work as advertised.

Check the SQL commands reference section of the manual for CREATE FUNCTION

Regards
Iain
----- Original Message -----
From: "Rod Taylor" <pg(at)rbt(dot)ca>
To: "Philippe Lang" <philippe(dot)lang(at)attiksystem(dot)ch>
Cc: <pgsql-sql(at)postgresql(dot)org>
Sent: Wednesday, October 20, 2004 10:05 PM
Subject: Re: [SQL] Reuse previously calculated column in sql query?

> On Wed, 2004-10-20 at 08:50, Philippe Lang wrote:
>> Hello,
>>
>> Is it possible to reuse a previously calculated column in a following
>> column, like:
>
> SELECT col1
> , col2
> , col2 * 0.75 AS col3
> FROM (SELECT foo.val1 AS col1
> , long_calculation(foo.val1) AS col2
> FROM foo) AS tab;
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html


From: sad <sad(at)bankir(dot)ru>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Offtopic: psql
Date: 2004-10-21 11:58:35
Message-ID: 200410211558.35936.sad@bankir.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Hi

Postgres has a perfect tool - psql
what libraries did you (developers) use to develop psql console and
particulary command-line editor.

thnx


From: Achilleus Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: sad <sad(at)bankir(dot)ru>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Offtopic: psql
Date: 2004-10-21 12:35:11
Message-ID: Pine.LNX.4.44.0410211534480.398-100000@matrix.gatewaynet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

O sad έγραψε στις Oct 21, 2004 :

> Hi
>
> Postgres has a perfect tool - psql
> what libraries did you (developers) use to develop psql console and
> particulary command-line editor.

% ldd `which psql`
maybe?

>
> thnx
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>

--
-Achilleus