Re: Parameter for query - Mailing list pgsql-general

From Luca Ferrari
Subject Re: Parameter for query
Date
Msg-id CAKoxK+7_R72R2vPwTLZHTm=RY0e7+PwxpBFR9E8hwWgsq55vnA@mail.gmail.com
Whole thread Raw
In response to Parameter for query  (Robert James <srobertjames@gmail.com>)
List pgsql-general
On Wed, Jul 17, 2013 at 6:25 AM, Robert James <srobertjames@gmail.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...
>

Using prepared statements? See here:
http://www.postgresql.org/docs/9.2/static/sql-prepare.html


> Currently, I need to do this in a scripting language.  Is there a
> straightforward way to do this directly in Postgres?

well, if you are doing this in a script(ing) it should be quite easy
to do string interpolation.

Luca


pgsql-general by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Parameter for query
Next
From: Luca Ferrari
Date:
Subject: Re: Driver Question