Re: Using Variables in Queries

From: Scott Mead <scottm(at)openscg(dot)com>
To: "Igal (at) Lucee(dot)org" <igal(at)lucee(dot)org>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using Variables in Queries
Date: 2017-10-19 15:25:01
Message-ID: CAKq0gvL=M-Yr7WwYLnqCk0nq41kO4CM2CL03EHLNgb9V-+=Nrw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Oct 19, 2017 at 11:21 AM, Igal @ Lucee.org <igal(at)lucee(dot)org> wrote:

> Hello,
>
> In other database servers, which I'm finally dropping in favor of
> Postgres, I can do the following (mind you that this is for illustration
> only, I do not actually write queries like that):
>
> DECLARE @query varchar(64) = 'red widget';
>
> SELECT *
> FROM products
> WHERE col1 LIKE @query
> OR col2 LIKE @query
> OR col3 LIKE @query
> OR col4 LIKE @query
> OR col5 LIKE @query
>
> The point is, though, that I can change the @query variable in one place
> which is very convenient.
>
> Is it still true (the posts I see on this subject are quite old) that I
> can not do so in Postgres outside of a stored procedure/function?
>

You can do this if you're using psql. This doesn't work if you're using
something like JDBC, etc..., but from psql it works great.

https://www.postgresql.org/docs/9.5/static/app-psql.html#APP-PSQL-VARIABLES

--Scott

> And if so, what's the reason of not adding this feature? Seems very
> useful to me.
>
> Thanks,
>
>
> Igal Sapir
> Lucee Core Developer
> Lucee.org <http://lucee.org/>
>

--
--
Scott Mead
Sr. Architect
*OpenSCG <http://openscg.com>*
http://openscg.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2017-10-19 15:37:32 Re: Using Variables in Queries
Previous Message Igal @ Lucee.org 2017-10-19 15:21:36 Using Variables in Queries