Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n5Myx-0003Na-HI for pgsql-general@arkaria.postgresql.org; Thu, 06 Jan 2022 07:14:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n5Myw-0008Rh-BM for pgsql-general@arkaria.postgresql.org; Thu, 06 Jan 2022 07:14:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n5Myv-0008RY-VT for pgsql-general@lists.postgresql.org; Thu, 06 Jan 2022 07:14:42 +0000 Received: from mail-ot1-x32c.google.com ([2607:f8b0:4864:20::32c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1n5Myt-00012N-QN for pgsql-general@lists.postgresql.org; Thu, 06 Jan 2022 07:14:41 +0000 Received: by mail-ot1-x32c.google.com with SMTP id o3-20020a9d4043000000b0058f31f4312fso2172833oti.1 for ; Wed, 05 Jan 2022 23:14:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=Ymd6augLy0Fza7KJNwjv/XIJOFubSKH0bcws5NFD2FU=; b=md88Bvd2myG++kCsFSI5XRaecVQdDVH07+y5ebPBg8c3scChmBZVUljO17jJVL6LiZ iSi0/s5KhkB2MBYf1OeEYMadBH1n+v6utzicBExUGEqv7VPOLDXbrQ3kgpwrhJBGn6zu LqhkFy1IXrQn+8jeQaFxsh6kx7h7YVAzAA7nWWAIKFBpIXziG4LW0+X85LkCl/BvCDC9 dLvtmpVu9Br0j1yfVowYVMSBfnwNd5nTFyvk/G4XvNxrvxSmD5MfGsuqiTtGW+W+VXB3 ggmjSy5/V331vBcVk9RoK8T6QkydPY26oUEVdYWfTlP8F67EThAxJKI/pq/W6CtznbVA EpRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=Ymd6augLy0Fza7KJNwjv/XIJOFubSKH0bcws5NFD2FU=; b=C6MKSNV0ZnqLrHbX98pAYDV1rmlYfEYCSIcHHI3JfDlKaKYqzwtlhHFnlZHZJ9+cDc HGPcyApXR6qI64pbqG2B3tQlKUSYp0O339UoJwwtCfsH7abkMFyfTkkSQulrGzJ+F6H/ AdcNLYYeqOej/aVrRVcII/WcI/4J3XYSNTYa9U8jaG+eIyAg+eGANyI5e6u/LvNeFXjZ kw1VQo2wvanettDp3u/foBiC82ThBS5bdvCtHN/CoEEe1THpapD0v2BKk/RfivgX8Nb/ ZpMZSCgktXLncAO62IE5qFEqUGqhcCamcLQ3nX6MM/t9O704C+zTACycb5fx//i5mbn7 EQ7w== X-Gm-Message-State: AOAM530x0dtJfIXdpP06+UNWWsqgTmjXadkFD9tiLi1vuCXOTLO47fTx DvQ2G1aeedISbevPWFvzW4NXyLMhGGs= X-Google-Smtp-Source: ABdhPJwidzfuxoWDQtNQkX9XDwb0bqtSACjYEpoPFDWd3V5Cfspf4Bpnh4QDoxZKYI/M2I7JPCS3pA== X-Received: by 2002:a9d:6a84:: with SMTP id l4mr40681228otq.216.1641453277780; Wed, 05 Jan 2022 23:14:37 -0800 (PST) Received: from [192.168.88.10] (ip68-11-68-85.no.no.cox.net. [68.11.68.85]) by smtp.googlemail.com with ESMTPSA id q19sm233181otk.34.2022.01.05.23.14.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 Jan 2022 23:14:37 -0800 (PST) Subject: Re: How to write such a query? To: Igor Korot Cc: "pgsql-generallists.postgresql.org" References: <489abaea-2a4b-8137-3366-ec6228656242@gmail.com> From: Ron Message-ID: <4c84d23f-5fd8-4060-e4db-cecd0ff072c2@gmail.com> Date: Thu, 6 Jan 2022 01:14:36 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------9C6681F277E15FC571127070" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------9C6681F277E15FC571127070 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 1/6/22 1:06 AM, Igor Korot wrote: > Hi, Ron, > > On Thu, Jan 6, 2022 at 1:01 AM Ron 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. --------------9C6681F277E15FC571127070 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit 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.
--------------9C6681F277E15FC571127070--