Re: Using Variables in Queries

From: Alban Hertroys <haramrae(at)gmail(dot)com>
To: Scott Mead <scottm(at)openscg(dot)com>
Cc: "Igal (at) Lucee(dot)org" <igal(at)lucee(dot)org>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using Variables in Queries
Date: 2017-10-19 15:37:32
Message-ID: CAF-3MvMURk1APP=UUR=BZqey4yLwHqjkyc7HcvQC68bpXBuMqg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 19 October 2017 at 17:25, Scott Mead <scottm(at)openscg(dot)com> wrote:
>
>
> 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 should be able to do that using the DO statement:
https://www.postgresql.org/docs/9.6/static/sql-do.html

--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2017-10-19 15:40:46 Re: Using Variables in Queries
Previous Message Scott Mead 2017-10-19 15:25:01 Re: Using Variables in Queries