Re: Using Variables in Queries

From: Pavel Stehule <pavel(dot)stehule(at)gmail(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:40:46
Message-ID: CAFj8pRDEqWSQ37S3xxpG4kR0Px-Q2duhEqBV+rT7gyRDBBBnVQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

2017-10-19 17:21 GMT+02:00 Igal @ Lucee.org <igal(at)lucee(dot)org>:

> 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? And if
> so, what's the reason of not adding this feature? Seems very useful to me.
>
Currently psql has client side variables. pgAdmin3 has some script language
too - https://www.pgadmin.org/docs/pgadmin3/1.22/pgscript.html Server side
variables are accessible only inside PLpgSQL variables.

There was lot of discussion about server side variables
https://wiki.postgresql.org/wiki/Variable_Design, but nobody write final
patch. There is not clean result if we want dynamic variables, static
variables or both.

p.s. Your query should be terribly slow. When I see it, I am less sure, so
server side variables are good idea :)

Regards

Pavel

> Thanks,
>
>
> Igal Sapir
> Lucee Core Developer
> Lucee.org <http://lucee.org/>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2017-10-19 15:44:58 Re: Using Variables in Queries
Previous Message Alban Hertroys 2017-10-19 15:37:32 Re: Using Variables in Queries