pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: Igor Korot <ikorot01@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: How to write such a query?
Date: Thu, 6 Jan 2022 01:14:36 -0600
Message-ID: <4c84d23f-5fd8-4060-e4db-cecd0ff072c2@gmail.com> (raw)
In-Reply-To: <CA+FnnTyOxFyXWRh2rdqO_jybnyTdXrmpq2dHskoe7ZdBVfA5Cg@mail.gmail.com>
References: <CA+FnnTzgQ3c75FE-eEPYVOa+F9N94jUpwW278ki_OeCJetovOA@mail.gmail.com>
	<489abaea-2a4b-8137-3366-ec6228656242@gmail.com>
	<CA+FnnTyOxFyXWRh2rdqO_jybnyTdXrmpq2dHskoe7ZdBVfA5Cg@mail.gmail.com>

On 1/6/22 1:06 AM, Igor Korot wrote:
> Hi, Ron,
>
> On Thu, Jan 6, 2022 at 1:01 AM Ron <ronljohnsonjr@gmail.com> wrote:
>> 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).
> Is the syntax available since 9.0+? Or later?
> I'm writing C++.

Like I said before... "the exact method depends on the client".  The C++ 
client */library/* is not the same as the psql *application*.

IOW, read the C+ client library documentation.

-- 
Angular momentum makes the world go 'round.

view thread (36+ messages)  latest in thread

Message-ID: <4c84d23f-5fd8-4060-e4db-cecd0ff072c2@gmail.com>
Permalink:  ../4c84d23f-5fd8-4060-e4db-cecd0ff072c2@gmail.com/
Also on:    postgresql.org/message-id/4c84d23f-5fd8-4060-e4db-cecd0ff072c2@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, ikorot01@gmail.com
  Subject: Re: How to write such a query?
  In-Reply-To: <4c84d23f-5fd8-4060-e4db-cecd0ff072c2@gmail.com>
  References: <CA+FnnTzgQ3c75FE-eEPYVOa+F9N94jUpwW278ki_OeCJetovOA@mail.gmail.com> <489abaea-2a4b-8137-3366-ec6228656242@gmail.com> <CA+FnnTyOxFyXWRh2rdqO_jybnyTdXrmpq2dHskoe7ZdBVfA5Cg@mail.gmail.com> <4c84d23f-5fd8-4060-e4db-cecd0ff072c2@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