Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tCnLj-00CvrZ-Uh for pgsql-general@arkaria.postgresql.org; Sun, 17 Nov 2024 22:02:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tCnLg-001k3j-D8 for pgsql-general@arkaria.postgresql.org; Sun, 17 Nov 2024 22:02:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tCnLe-001k3b-N5 for pgsql-general@lists.postgresql.org; Sun, 17 Nov 2024 22:02:28 +0000 Received: from fhigh-b7-smtp.messagingengine.com ([202.12.124.158]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tCnLb-002Pt0-OI for pgsql-general@lists.postgresql.org; Sun, 17 Nov 2024 22:02:25 +0000 Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.stl.internal (Postfix) with ESMTP id 2C841254014F; Sun, 17 Nov 2024 17:02:22 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Sun, 17 Nov 2024 17:02:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1731880942; x=1731967342; bh=CPXGFwqIJoskqWpJ5JZCfbsXKKHMWV2FNrHAk/VyEAs=; b= InlrmUo26n93x27faDpN1E/su2v0hMbWVHd1kUCsYuDJ4u+7oXGcRolG2NIeJ1RR eRU0xzxkHpX1twQ1+9x1p6jB6QBq9h11jayGpNRkMnK9amsqcLd51hJ/sx1DSOcO Ryl418XwDes06tZfCG9ujomeEY4qP02xtsB5EwKpHrldrz+t1RfA4vBdVC+1wUh7 tcrpY3QA5OHXvFfCTLyRnKyVAWjOv1l/hDKE5nY3FP68XkiOptM8GXWDBSii5e4I Hkqy1G1/6JMM/pzfaci1ALwu+SqDKTOcR0LiBL7Iv1oZQex2j0BEZCHCBZ9nnTPi 6UkfbvRDRlkKr6Vd0oPfQw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1731880942; x=1731967342; bh=C PXGFwqIJoskqWpJ5JZCfbsXKKHMWV2FNrHAk/VyEAs=; b=PBi7P3oPCASRw8KAd 0mFAkp+jyBHUpILm5paplC10BmQub948Xi4BYcpo0Vx0/vdsrTHi4wUglBZDwbEe uHphciu1kP8F4YFghQu9A/njjkDNcSwnREbwo3tuVQiT647zam5eOq7igYOb6tqo 3R4LSzGGMtaCV5+I/kV5MYTrE90JtAFSY5ZL8pMZEG0Kvtof4ja3sTpdPgYOKoAO eldqxZzCew7BuPFSdO7UBUUOZ0I3s/0jwPwAOcT+jbzijCP6osq2Nw/chCpp2SjU kAs6K9r+2zEW33rc275PEWoupohTBRDZ+6cWGw9slZ+jLAIpPxi3j2kj1FsyvdqY enhFw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrvdekgdduheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttddvjeen ucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrse grkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpedulefghfelgeeuteelfeet ueeiffegtdekvdeltdeuueelvddtkefgvdeigfeigfenucffohhmrghinhepphhshigtoh hpghdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhr ohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmpdhnsggprhgtph htthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegrrdhmrghnthiiihho shestghlohhuugdrghgrthgvfigrhihnvghtrdgtohhmpdhrtghpthhtohepphhgshhqlh dqghgvnhgvrhgrlheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 17 Nov 2024 17:02:20 -0500 (EST) Message-ID: Date: Sun, 17 Nov 2024 14:02:19 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Getting error 42P02, despite query parameter being sent To: Achilleas Mantzios , pgsql-general@lists.postgresql.org References: <40d8beef-ff67-4c6c-828c-2941ca30fdef@cloud.gatewaynet.com> <574887e1-21a3-4847-9933-c05ac56edde2@aklaver.com> <67041789-6c66-4fde-acdf-0db3f6842b35@cloud.gatewaynet.com> Content-Language: en-US From: Adrian Klaver In-Reply-To: <67041789-6c66-4fde-acdf-0db3f6842b35@cloud.gatewaynet.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/17/24 11:44, Achilleas Mantzios wrote: > > Στις 16/11/24 18:09, ο/η Adrian Klaver έγραψε: >> On 11/16/24 03:15, Achilleas Mantzios wrote: >>> >>> Στις 16/11/24 12:55, ο/η Max Ulidtko έγραψε: >>>> Greetings, group! >>>> >>>> I'm trying to understand a low-level issue. Am evaluating a new >>>> client library for Postgres; it's not particularly popular / >>>> mainstream, and as I've understood so far, sports an independent >>>> implementation of PG binary protocol. >>>> >>>> The issue I'm hitting with it is exemplified by server logs like this: >>>> >>>> 2024-11-16 10:28:19.927 UTC [46] LOG: statement: SET client_encoding >>>> = 'UTF8';SET client_min_messages TO WARNING; >>>> 2024-11-16 10:28:19.928 UTC [46] LOG: execute : CREATE VIEW >>>> public.foobar (alg, hash) AS VALUES ('md5', $1); >>> >>> At least for SQL level prepared statements the statement has to be >>> one of : >>> >>> |SELECT|, |INSERT|, |UPDATE|, |DELETE|, |MERGE|, or |VALUES| >>> >>> |so CREATE is not valid, and I guess the extended protocol prepared >>> statements aint no different in this regard. >> >> It would seem so. Using psycopg: >> >> import psycopg >> from psycopg import sql >> >> con = >> psycopg.connect("postgresql://postgres:postgres@127.0.0.1:5432/test") >> cur = con.cursor() >> cur.execute("CREATE VIEW public.foobar (alg, hash) AS VALUES ('md5', >> %s)", ['test']) >> >> IndeterminateDatatype: could not determine data type of parameter $1 >> >> cur.execute(sql.SQL("CREATE VIEW public.foobar (alg, hash) AS VALUES >> ('md5', {})").format(sql.Literal('test'))) >> >> con.commit() >> >> cur.execute("select * from foobar") >> cur.fetchone() >> >> ('md5', 'test') > > I dont know python but this does not look like a solid prepared statement. > > https://www.psycopg.org/psycopg3/docs/advanced/prepare.html > > Does not seem to have used the prepared statement circuitry. > The second example is not and was not meant to be. It was meant to show how you could dynamically create an SQL statement when it will not accept parameters. FYI, this was run using psycopg(3) which does things differently, by default, then psycopg2. For full explanation see: https://www.psycopg.org/psycopg3/docs/basic/from_pg2.html Server-side binding -- Adrian Klaver adrian.klaver@aklaver.com