Re: Parameter for query

From: Luca Ferrari <fluca1978(at)infinito(dot)it>
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 06:03:48
Message-ID: CAKoxK+7_R72R2vPwTLZHTm=RY0e7+PwxpBFR9E8hwWgsq55vnA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jul 17, 2013 at 6:25 AM, 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...
>

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Xiang Jun Wu 2013-07-17 07:10:37 About postgres scale out
Previous Message Michael Paquier 2013-07-17 04:36:41 Re: Parameter for query