Re: Using Variables in Queries

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(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:44:58
Message-ID: CAKFQuwbTrD-xN2pX7DamDAbCWqxGjobrZQAStAZr7D4NrezByA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Oct 19, 2017 at 8:21 AM, Igal @ Lucee.org <igal(at)lucee(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message rob stone 2017-10-19 17:11:55 Re: Problems with the time in data type timestamp without time zone
Previous Message Pavel Stehule 2017-10-19 15:40:46 Re: Using Variables in Queries