pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: How to write such a query?
Date: Thu, 6 Jan 2022 01:00:53 -0600
Message-ID: <489abaea-2a4b-8137-3366-ec6228656242@gmail.com> (raw)
In-Reply-To: <CA+FnnTzgQ3c75FE-eEPYVOa+F9N94jUpwW278ki_OeCJetovOA@mail.gmail.com>
References: <CA+FnnTzgQ3c75FE-eEPYVOa+F9N94jUpwW278ki_OeCJetovOA@mail.gmail.com>

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.





view thread (36+ messages)  latest in thread

Message-ID: <489abaea-2a4b-8137-3366-ec6228656242@gmail.com>
Permalink:  ../489abaea-2a4b-8137-3366-ec6228656242@gmail.com/
Also on:    postgresql.org/message-id/489abaea-2a4b-8137-3366-ec6228656242@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: How to write such a query?
  In-Reply-To: <489abaea-2a4b-8137-3366-ec6228656242@gmail.com>
  References: <CA+FnnTzgQ3c75FE-eEPYVOa+F9N94jUpwW278ki_OeCJetovOA@mail.gmail.com> <489abaea-2a4b-8137-3366-ec6228656242@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox