Re: Let-bindings in SQL statements
От | David Johnston |
---|---|
Тема | Re: Let-bindings in SQL statements |
Дата | |
Msg-id | 006101ccdc39$d074e4b0$715eae10$@yahoo.com обсуждение исходный текст |
Ответ на | Let-bindings in SQL statements (Jon Smark <jon.smark@yahoo.com>) |
Список | pgsql-general |
-----Original Message----- From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Jon Smark Sent: Thursday, January 26, 2012 9:38 AM To: pgsql-general@postgresql.org Subject: [GENERAL] Let-bindings in SQL statements 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 ----------------------------------------------------------------------- No, not really. In some cases you can use a CTE (WITH) clause to create a single row with whatever names and values you need and then, using Sub-Selects or CROSS JOIN, introduce that row into the appropriate parts of the query. David J.
В списке pgsql-general по дате отправления: