Re: How to write such a query? - Mailing list pgsql-general

From Ron
Subject Re: How to write such a query?
Date
Msg-id 489abaea-2a4b-8137-3366-ec6228656242@gmail.com
Whole thread Raw
In response to How to write such a query?  (Igor Korot <ikorot01@gmail.com>)
Responses Re: How to write such a query?  (Igor Korot <ikorot01@gmail.com>)
List pgsql-general
On 1/6/22 12:39 AM, Igor Korot wrote:
> Hi, ALL,
> In SQLite you can write:
>
> SELECT a, b, c FROM foo WHERE id = :id;
>
> where ":id" is the named parameter.
>
> The query above is similar to
>
> SELECT a,b,c FROM foo WHERE id = ?;
>
> except that the parameter has a name.
>
> Is there a way to write such a SELECT statement with the
> named parameter in PostgreSQL?
Absolutely.  Of course, the exact method depends on the client.  Are you 
referring to psql?

If so, then here's an example:
$ psql12 -v S=456789012 test
psql (12.8 (Ubuntu 12.8-1.pgdg18.04+1))
Type "help" for help.

test=# select * from employee where ssn = :'S';
     ssn    |      name       |  ssn_int
-----------+-----------------+-----------
  456789012 | Fred Flintstone | 456789012
(1 row)

In this case, column ssn is of type varchar(9).

-- 
Angular momentum makes the world go 'round.



pgsql-general by date:

Previous
From: Amul Sul
Date:
Subject: Re: How to write such a query?
Next
From: Igor Korot
Date:
Subject: Re: How to write such a query?