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 1maeYU-0001Dj-P2 for psycopg@arkaria.postgresql.org; Wed, 13 Oct 2021 13:44:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1maeYT-0003LO-Jr for psycopg@arkaria.postgresql.org; Wed, 13 Oct 2021 13:44:25 +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 1mae2d-00046l-Lb for psycopg@lists.postgresql.org; Wed, 13 Oct 2021 13:11:31 +0000 Received: from mx0a-001b6a02.pphosted.com ([205.220.164.217]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mae2V-0007aT-Ds for psycopg@postgresql.org; Wed, 13 Oct 2021 13:11:30 +0000 Received: from pps.filterd (m0214201.ppops.net [127.0.0.1]) by mx0b-001b6a02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19DCA2NC002600 for ; Wed, 13 Oct 2021 09:11:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadridge.com; h=from : to : cc : subject : date : message-id : content-type : mime-version; s=pps1; bh=W2tOXdOmcW7c0+i70+n8BVXghzcs2oVT2wZnmOLDr/4=; b=0RBHaZT3DYCK/DzheR+RNpM58oi3jN8Irbvix4cT8Q0KgSZHYCno0Y7yrF2gWDFCKRuk //AbtXya1asroDW6tmVyuyE24FDxdbRp0M1JYsQwCppXwONfRW583PjWym0tAKu+rUos Ja3GaCJBDM0tQsXyqRy2WoFOdW1eXWvHZYixl2gQXq8Qp28yc9PTnfOnxia/UsJiOaP1 /UiRFvAeJal006mkJ9fzE8D+LVTObgoDk48Rj2H6uZyr/mkXeIl9IQgnvR2lC8lEc3vF 96ZCqyeeKMIOUMxLJNb6GWCHHWOjNLzkbGQeojulkMYbrhly1MuRsatqgU1pNY+aLLED DA== Received: from gwm.broadridge.com (central4-gwm.broadridge.com [167.212.42.154]) by mx0b-001b6a02.pphosted.com with ESMTP id 3bny7jr4n6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 13 Oct 2021 09:11:19 -0400 Received: from CLIPSWEXMAA3.bsg.ad.adp.com (10.17.79.157) by CLIPSWEXMAA5.bsg.ad.adp.com (10.17.79.159) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 13 Oct 2021 09:11:16 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (10.25.150.24) by CLIPSWEXMAA3.bsg.ad.adp.com (10.17.79.157) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14 via Frontend Transport; Wed, 13 Oct 2021 09:11:16 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oIlQCIk8/4gaP/De3kwGYq0nq1mY8HeDIDRW8x/wsnTMuvxfjA3zNZnWIFOOWvNSUvzdO/AWtU0qCDi5+q9w58bZMU/HIp7xqLE+i6Kd9FnCb13mdQ+sDcSgNM0MuABHxlskwnqk5V1fdCP80+ndTLntHCdcy2yPAsjKwZbGHYtF1bV9FK0yRHBcbPQ14E/Xp3eaSnjgH+gm5q3C319u8ptQAm6m0qT5lHpIYkMl0gAwLC/R65nJexbBEHaAbu4PxGVMSN5XHGMt30kIW//lE9IUcooRBSr42v9Cv67BBNG6uymhkXIvcyuL/n0a6/33quUDPuWKzuUl+ZpV0Ft6EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=sjOCvQQQ11qODRDA/MKnGwPdsF3cgNZ9Z8RCBTIxE7w=; b=g6T7/GQiboASneMT+OE5uMJl+MG+PVsspM+pTjYUv9TA/BdzW7YK8gCrlaC3wbS2GTADXoEQ4SE0QawlldRBf72wGhp27wRE7Kn3MV7tMFagDiKPKSzVRIdxTfyuCGgA3tjfVvGLmfFfZMO4WXLdntPM5vr3khcHKH+wGlY5YNG/eYfMwVn6wpP1qnw7IGlp/Rmp4quZXmXIzyLQJK//QT5vdMSzbOKZkOxc/FV5nBtqiJnCs1t12QgCWwsEZluCaeqreShxXEEpxPNCqQyH9UsvFNk3GN19bhdiYcvHJs6wpjmSFtvgDSJHmBy5cULEiQExQkm+7TziDinTTThHvA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=broadridge.com; dmarc=pass action=none header.from=broadridge.com; dkim=pass header.d=broadridge.com; arc=none Received: from BN0PR20MB3912.namprd20.prod.outlook.com (2603:10b6:408:12e::18) by BN8PR20MB2451.namprd20.prod.outlook.com (2603:10b6:408:d1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Wed, 13 Oct 2021 13:11:14 +0000 Received: from BN0PR20MB3912.namprd20.prod.outlook.com ([fe80::4d48:8e86:259d:afc2]) by BN0PR20MB3912.namprd20.prod.outlook.com ([fe80::4d48:8e86:259d:afc2%8]) with mapi id 15.20.4608.016; Wed, 13 Oct 2021 13:11:14 +0000 From: "Lembark, Steven" To: "psycopg@postgresql.org" CC: "Loga, Dharani" Subject: Using standard SQL placeholders in PG Thread-Topic: Using standard SQL placeholders in PG Thread-Index: AdfAM3VxI+kFbOwTT6+PKFw9q9wVOA== Date: Wed, 13 Oct 2021 13:11:14 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: postgresql.org; dkim=none (message not signed) header.d=none;postgresql.org; dmarc=none action=none header.from=broadridge.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 309bfbcc-fe23-44c2-2857-08d98e4aef90 x-ms-traffictypediagnostic: BN8PR20MB2451: x-ld-processed: a3198c8c-0642-4649-849d-daacc3298f83,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 6q4WgvzE8X4gMC4+qVPGMfiSyzl//SgH6we+lHhHsoCa3KCrB+fAHXoA9t0HUfsQlzNDr+FSB9P7TNvYJvW99BPNEKmHVj1mGdv9kySe2Dtrsucua9a5lVMkT4N3XbhWvTvSIKVJior1d8n5PpUR57ILZxr4ZjwZR5UtlrFtpu5CphSJX2HaOHr8Of8lZsg/aSp6nzGo9angH+Obh7rhe7wxwaV1zcfckNsUmMl4ZWjdTRP2dejqFtZa8MzcD64UzyiEb/q6pQn+wp5QCYlIIUPfv0nUVdUOlTF48SUmovO6kdiebOqTluLCqKtJk5ndry6Vmf78PswaLYkDxKOSfToDnrfsjqJhcY88nZa87zlsgxPa/DTyyqWy6/nDh577TVBfOGLRLCefuwo4rkDqz3+6OYutiZV5xqqIovmrEJutjYyE/c1csIDZS8Rakruxp9c7AkZ4V8M26/5eCC8SuvijE+r1HfmaDB5y406UnaoBJuvx6nxS1LgXW2gnb6UfqToRePhsWjVyxOIslkJNlIjSikcCt0o539wTWJZts/27H9Nf54dc5lAMoyEDVtIQHXUmMfx5fnXe/Jby8llaM6fLXZUsXQfysetDv9Hf/iMXRuEY0CDgd0lkoaOYNacGHfbt1+JysNhp+wmhk54P9kGDLuKv+8mTpKqu7pYmdgEZ2EsrTV+wuSAFEQPnDie6clEMABIZHHK8eyq1mHQt7A== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN0PR20MB3912.namprd20.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(52536014)(5660300002)(86362001)(33656002)(4744005)(316002)(6506007)(8936002)(9686003)(66476007)(7696005)(186003)(8676002)(55016002)(64756008)(66946007)(38100700002)(508600001)(66556008)(38070700005)(2906002)(107886003)(4326008)(66446008)(76116006)(26005)(122000001)(71200400001)(6916009);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?m8b+xM9L/l+UVeIIFzNAdm9FvsHOPlQ1E0LAL8XWdiOdFGqsyzleG29nc+3W?= =?us-ascii?Q?cREF7UFHcpHI3pSox9cbzTKFMAR2uV4Xp9i9+TEYdwa0KtuikHqW8P+MzD25?= =?us-ascii?Q?GSOUW+0nUEW7Y+CJ8Wn+lfqSMQ4m4TL1RNF1qtdNRNL5pw1+x+bg07gtBNPH?= =?us-ascii?Q?4YL35no4r2li0zvNX5oSgjgcmT9CvpBsh9Awv0ToYZtSygj+QLZE8mug8Jfn?= =?us-ascii?Q?2Rcv9Qf1QjYiK/mE6JXxd33FusFzp4nEuC0/13B2YNh0fLv7BY+tzKw3Tg6E?= =?us-ascii?Q?5MqeM4Uv9xllJ+OcSxHt8/Ga3WU0uJboqNhREv8ZqiXC3nqwVEmkBzXPi2dO?= =?us-ascii?Q?LqMYJ1uv/4sJ5M1YeZGa6oVT24V21nMBiIDwNF08CeqziZ0Vs8T/u1NNO+Ss?= =?us-ascii?Q?Rcb1daAe9Bw2uRY/PSL0scSjM8d2prQ3Ka20a9cTpqDdReU9usq98ApeLYhW?= =?us-ascii?Q?eWfuvAmDi/B0XIyb4NNE//3oHwyIFT7SQXzGIpU2xjBxvOfSXwSlMoh+Q/3M?= =?us-ascii?Q?xQRQJ+jPElWXYJMPhaqxa00fU0hHy8Owx76GZJ4tzV5ono1Eu1T+Lld8FEwg?= =?us-ascii?Q?FPg5I6Yugm2w+Rd24svVVlMDxkEGfBFmlU7N2fvo1cOtghvgynycLtktmIoD?= =?us-ascii?Q?vA4obcY0wQmWW4UDaKqkBcjeItxvvwsdGEOM/KxXZtgvQwVif3yZIqx6KeKL?= =?us-ascii?Q?DcEWTnZiyrCHLh2F9H8gIZFPhiGIw018AWOLg9ZsViw21Uam6gMOSK7a/HoJ?= =?us-ascii?Q?u0HKlXBYebwRb3c0dimmZ0X3Km+rp0r1Dd0tdRF7yAiVOXdAqcPREgjrnwA7?= =?us-ascii?Q?BuqVPWZ8ccrp0khGDBkRfcDUIquYyuRgLZOW4/vQgOd1s3VPz7dtDebm+vWj?= =?us-ascii?Q?503SqUtSRarz+JDj4spy2EkIKgnCSAAZ/yhOPr04f0UUNkNda9yQ7LcWbo0O?= =?us-ascii?Q?b+D6UNP3d5ONXc8U7JMI+rdI+fgYDD8rj1rN0H4z4+CtnhsYJdZdAfTXOtpT?= =?us-ascii?Q?6LPLEa/O/tP8Au5DA+pa4+UxAvrHume93tvcpf4ShOLySUzzhOS8IUvNcXyK?= =?us-ascii?Q?3K9sC84EdTa2At+RZiZ4UqaY1ue0+OhK63CEzW2gB4YjylzZC1CAa8XB/UhT?= =?us-ascii?Q?rpYqgKFKUAvxo20x29xt52sChrsJQQQWswCg6KFDh6wsJL+G8n3Lbzins9nN?= =?us-ascii?Q?+oBSlVxRVp2nAunZz+uTdAfcwFIHO3TpJQu/GNoEi1+Q6CUSJt65p7ZZoo9F?= =?us-ascii?Q?T5Jn8UFxxS11/1g6QtMLalGU2758noPvZqoP3s/3KzK47Q1TaKQOeY+r6wcF?= =?us-ascii?Q?wiWlV6TUDSGfgI/cnxqchTXF?= Content-Type: multipart/alternative; boundary="_000_BN0PR20MB391249E4640F43A8A14B84A4FDB79BN0PR20MB3912namp_" MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN0PR20MB3912.namprd20.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 309bfbcc-fe23-44c2-2857-08d98e4aef90 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Oct 2021 13:11:14.6158 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a3198c8c-0642-4649-849d-daacc3298f83 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: fWztC7cQu9HwTcjjP7K0UrUvg+LajP7B7XM1B1wZvyiE6yt3qL1MHidOIms7o1C5YdezLkLmOJQWBEFcDNW1IgbelmRXFpn4v3n8Ukwf2s8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR20MB2451 X-OriginatorOrg: broadridge.com X-SYMANTEC-INSPECTED: YES X-Proofpoint-GUID: CQoq-xS0RvExKXoddTZV3h0nV63BY6f6 X-Proofpoint-ORIG-GUID: CQoq-xS0RvExKXoddTZV3h0nV63BY6f6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-10-13_05,2021-10-13_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 phishscore=0 mlxscore=0 priorityscore=1501 adultscore=0 mlxlogscore=586 impostorscore=0 clxscore=1011 bulkscore=0 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110130088 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --_000_BN0PR20MB391249E4640F43A8A14B84A4FDB79BN0PR20MB3912namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable PostgreSQL ("PG") supports the notion of placeholders, as do many other rel= ational databases. The placeholder notation in PG uses $X within the SQL. F= or example: select foo from bar where bletch =3D $1 is valid SQL. The doller-notation allows re-use of positional parameters an= d avoids SQL injection entirely by placing the input is appropriately-typed= buffers w/in the SQL statement handler. It also avoids issues with double-= interpolating quotes as the placeholders are not literals and do not requir= e SQL-quoting to be interpolated properly. We have quite a bit of SQL here that has to be shared between Python and ot= her packages, so using standard PG SQL statements is required. Q: Is there any way to prepare and execute standard PG SQL statements with = dollar placeholders in PsychoPG2? Thanks This message and any attachments are intended only for the use of the addre= ssee and may contain information that is privileged and confidential. If th= e reader of the message is not the intended recipient or an authorized repr= esentative of the intended recipient, you are hereby notified that any diss= emination of this communication is strictly prohibited. If you have receive= d this communication in error, please notify us immediately by e-mail and d= elete the message and any attachments from your system. --_000_BN0PR20MB391249E4640F43A8A14B84A4FDB79BN0PR20MB3912namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

PostgreSQL ("PG") supports t= he notion of placeholders, as do many other relational databases. The place= holder notation in PG uses $X within the SQL. For example:

select     foo

from     &nbs= p; bar

where      bl= etch =3D $1

 

is valid SQL. The doller-notation allo= ws re-use of positional parameters and avoids SQL injection entirely by pla= cing the input is appropriately-typed buffers w/in the SQL statement handler. It also avoids issues with double-interpol= ating quotes as the placeholders are not literals and do not require SQL-qu= oting to be interpolated properly.

 

We have quite a bit of SQL here that h= as to be shared between Python and other packages, so using standard PG SQL= statements is required.

 

Q: Is there any way to prepare and exe= cute standard PG SQL statements with dollar placeholders in PsychoPG2?=

 

Thanks

 

This message and any attachments are intended only for the use of the addre= ssee and may contain information that is privileged and confidential. If th= e reader of the message is not the intended recipient or an authorized repr= esentative of the intended recipient, you are hereby notified that any diss= emination of this communication is strictly prohibited. If you have receive= d this communication in error, please notify us immediately by e-mail and d= elete the message and any attachments from your system.
--_000_BN0PR20MB391249E4640F43A8A14B84A4FDB79BN0PR20MB3912namp_--