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 1n5MnS-0002vv-NR for pgsql-general@arkaria.postgresql.org; Thu, 06 Jan 2022 07:02:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n5MnR-0001kh-L1 for pgsql-general@arkaria.postgresql.org; Thu, 06 Jan 2022 07:02:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n5Mli-0003AC-3g for pgsql-general@lists.postgresql.org; Thu, 06 Jan 2022 07:01:02 +0000 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1n5Mlb-0000NE-Ab for pgsql-general@lists.postgresql.org; Thu, 06 Jan 2022 07:01:00 +0000 Received: by mail-ot1-x32b.google.com with SMTP id p8-20020a9d7448000000b005907304d0c5so2115015otk.6 for ; Wed, 05 Jan 2022 23:00:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=JvXvCn+o4Sp9cD350MN1Pl3vIvmquuV+0DvW7NiR9gs=; b=Wu4Jaw3CUw8Db2wzJcb8+CWbKga3DXSKr8dEElG3Q70BEQFLapCN+oTUdJrmcurWAk msiOcN5GivtJNK64Q7b77T49sYVA/DUq9iqty1/2b/nAz97os2wsnXrwaKGVgVvK2/bk GmmPm2itHaju2YJrRv244/6JauNRSfRboY/zHDKZuHFll23kivF2XOF58YRgb8W1yIwn /y2G88MGm1n71YIAaeI7MLPxqvOShh/s2ZDm7uEgkAD+kpU1rw/AeL2loVgfaQ06mwA4 CPpUwSHwlu0PWVNdqM8TAT/nY9sVHat8+h7yLgjbbX8tNYZSL6gXGxvp7QET5Da/Escu Hecw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=JvXvCn+o4Sp9cD350MN1Pl3vIvmquuV+0DvW7NiR9gs=; b=XvsksAsogDDb3sCe5sp3RfJ+I27YpwQuoMzRHSRGVAXL0kmp5CcFh4MdS6ICh1Mvvu I2gy46lXRRnUD6Bm4frNNtlUUGx/v+vQxhBPD99cLXkwXvLM0Qk7gSV69wjqLIawEJ47 iJ6s/0bS8LW+px+Jz/dwtaWV6M/T85E9ejgi+3KTbAOK3RoAcy0f5EisiRvPZrX7JJgx IrpdvXXQ9QOMvOi4eyJdQXLtLjVHldppnR2wZ1kyh7Q6KvolVU91gAYFU9xKYD/0en6e 2CmanNZj+mDyoe+1rt89n83HzC0nUoX+1eG+aDa4eD2k2KeYRhh1do2CKQX2BTharKxI CqKQ== X-Gm-Message-State: AOAM530hnbxnLAHtUymOev3+nquixflltFDNbBf3tnkUfBl9FJZAW08g oJ892iEaMg13Qq/oOTLpIcAFygsJk9U= X-Google-Smtp-Source: ABdhPJw0URn40eSjA2OmjJoSmj7s5idci1rcjeNvU8qK1y84gHvs3TGIdok8Xw2IC89cEdBBCpgpzw== X-Received: by 2002:a9d:266a:: with SMTP id a97mr4062193otb.301.1641452454259; Wed, 05 Jan 2022 23:00:54 -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 184sm254408oih.58.2022.01.05.23.00.53 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 Jan 2022 23:00:53 -0800 (PST) Subject: Re: How to write such a query? To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: <489abaea-2a4b-8137-3366-ec6228656242@gmail.com> Date: Thu, 6 Jan 2022 01:00:53 -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: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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.