Re: [GENERAL] Using Variables in Queries - Mailing list pgsql-general

From David G. Johnston
Subject Re: [GENERAL] Using Variables in Queries
Date
Msg-id CAKFQuwbTrD-xN2pX7DamDAbCWqxGjobrZQAStAZr7D4NrezByA@mail.gmail.com
Whole thread Raw
In response to [GENERAL] Using Variables in Queries  ("Igal @ Lucee.org" <igal@lucee.org>)
Responses Re: [GENERAL] Using Variables in Queries  ("Igal @ Lucee.org" <igal@lucee.org>)
List pgsql-general
On Thu, Oct 19, 2017 at 8:21 AM, Igal @ Lucee.org <igal@lucee.org> wrote:

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.

​<not positive on syntax but the concept should be sound>​

​PREPARE sqlquery AS​ SELECT * FROM products WHERE col1 LIKE $1 OR col2 LIKE $1;
EXECUTE sqlquery('red widget');

Alban's DO blocks are problematic since they are incapable of generating a result set.

As Scott said people needing this functionality in PostgreSQL are content with using psql.

Adding lots of new custom syntax to pure server-side parsed SQL is a non-trivial undertaking whose need is reduced by the alternatives so described (functions, DO block, PREPARE, psql).

David J.

pgsql-general by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: [GENERAL] Using Variables in Queries
Next
From: rob stone
Date:
Subject: Re: [GENERAL] Problems with the time in data type timestamp withouttime zone