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.96) (envelope-from ) id 1wOFLc-001QmT-2d for pgsql-general@arkaria.postgresql.org; Sat, 16 May 2026 13:46:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wOFLb-0032JN-2G for pgsql-general@arkaria.postgresql.org; Sat, 16 May 2026 13:46:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wOFLb-0032JF-1J for pgsql-general@lists.postgresql.org; Sat, 16 May 2026 13:46:31 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wOFLZ-00000000vr6-1X39 for pgsql-general@lists.postgresql.org; Sat, 16 May 2026 13:46:31 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 64GDkR0h1495293; Sat, 16 May 2026 09:46:27 -0400 From: Tom Lane To: Igor Korot cc: "pgsql-generallists.postgresql.org" Subject: Re: Double prepare In-reply-to: References: Comments: In-reply-to Igor Korot message dated "Sat, 16 May 2026 01:40:32 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1495291.1778939187.1@sss.pgh.pa.us> Date: Sat, 16 May 2026 09:46:27 -0400 Message-ID: <1495292.1778939187@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Igor Korot writes: > Is there a way to see if the query has been prepared already (in libpq)? Use the pg_prepared_statements view. I don't think libpq keeps any client-side state about this. > Or is it better to run PQprepare for all known parameterized queries > in the very beginning of the program and just execute them when needed? Very probably. Querying pg_prepared_statements every time would be expensive. regards, tom lane