Re: How to write such a query?

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: Igor Korot <ikorot01(at)gmail(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: How to write such a query?
Date: 2022-01-06 07:14:36
Message-ID: 4c84d23f-5fd8-4060-e4db-cecd0ff072c2@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/6/22 1:06 AM, Igor Korot wrote:
> Hi, Ron,
>
> On Thu, Jan 6, 2022 at 1:01 AM Ron <ronljohnsonjr(at)gmail(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dmitry Igrishin 2022-01-06 08:17:07 Re: How to write such a query?
Previous Message Igor Korot 2022-01-06 07:14:31 Re: How to write such a query?