Let-bindings in SQL statements

From: Jon Smark <jon(dot)smark(at)yahoo(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Let-bindings in SQL statements
Date: 2012-01-26 14:37:49
Message-ID: 1327588669.84153.YahooMailNeo@web112810.mail.gq1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

Is it possible to do the equivalent of let-bindings in a pure SQL function?
I have a SELECT that invokes "now" multiple times.  It would be nicer
to do it only once and reuse the value.  Something like this:

LET right_now = SELECT now () IN
SELECT * FROM my_table WHERE right_now >= start AND ...

In PL/pgSQL this is easy, but I wonder about SQL...

Thanks in advance!
Jon

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Szymon Guz 2012-01-26 14:41:25 Re: Let-bindings in SQL statements
Previous Message salah jubeh 2012-01-26 13:51:18 How to push predicate down