From: | Michael Paquier <michael(dot)paquier(at)gmail(dot)com> |
---|---|
To: | Robert James <srobertjames(at)gmail(dot)com> |
Cc: | Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Parameter for query |
Date: | 2013-07-17 04:36:41 |
Message-ID: | CAB7nPqTv+RCkoEziL+PLZHh3xGeB8PTEAEeH79wztEV0cBComg@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, Jul 17, 2013 at 1:25 PM, Robert James <srobertjames(at)gmail(dot)com> wrote:
> Is there any way to set a variable or parameter for a query?
>
> I have a long query where a certain variable needs to be easy to
> change. I'd like to do something like:
>
> threshold = 10.3
>
> SELECT... WHERE x > $threshold... AND y * 1.3 > $threshold...
>
> Currently, I need to do this in a scripting language. Is there a
> straightforward way to do this directly in Postgres?
Using which client? psql? In this case there is that:
http://www.postgresql.org/docs/devel/static/app-psql.html#APP-PSQL-INTERPOLATION
postgres=# \set foo 1
postgres=# select :foo;
?column?
----------
1
(1 row)
mpaquier=# \set foo bar
mpaquier=# select :'foo';
?column?
----------
bar
(1 row)
Regards,
--
Michael
From | Date | Subject | |
---|---|---|---|
Next Message | Luca Ferrari | 2013-07-17 06:03:48 | Re: Parameter for query |
Previous Message | Robert James | 2013-07-17 04:25:38 | Parameter for query |