Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 83A7C64FC5F for ; Sun, 28 Dec 2008 08:19:33 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 83373-05 for ; Sun, 28 Dec 2008 08:19:30 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from qw-out-2122.google.com (qw-out-2122.google.com [74.125.92.27]) by mail.postgresql.org (Postfix) with ESMTP id 8223F64FC5E for ; Sun, 28 Dec 2008 08:19:30 -0400 (AST) Received: by qw-out-2122.google.com with SMTP id 8so1620121qwh.61 for ; Sun, 28 Dec 2008 04:19:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type; bh=pcfie1iS57hMcaOTeNwS2lCsMgiqLOqtBJDzNlV8wf0=; b=eU/7QmCzVLQ7HRu67othgDQqAGbcpj/kAIaiEvvLVu1FuUh6KOLe5sRypivJQZ5sBg yxdReipriA94mR0N5uqZbTQSPyyq93mpwmyxyJ41iueUQqwsPMCQqUi94o4FW8ey7VZA oK/kfY97XN1tvAEtm0NCT3m1N5DaB2BPWmxyg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=oesUByDPF/YncCGuyI/+XFd0otddHW7shO9v4sYX3wWv0al6qCdQrHkdSIyWA8BS04 rtAA2GFlPkgmDC+ZWGHms4xby+dNusyH7Ll3rzkhdSZTurwbGUsZfiQc4E2JUXueiAZU efFmyURCDgV2jWqbObQ084HiYKFRRl3Be1U9c= Received: by 10.215.39.20 with SMTP id r20mr10506434qaj.216.1230466769109; Sun, 28 Dec 2008 04:19:29 -0800 (PST) Received: by 10.215.40.21 with HTTP; Sun, 28 Dec 2008 04:19:29 -0800 (PST) Message-ID: <2fa647f60812280419t3c54d14bgd1612354e789b50c@mail.gmail.com> Date: Sun, 28 Dec 2008 13:19:29 +0100 From: "Thue Janus Kristensen" To: pgsql-interfaces@postgresql.org Subject: Getting a list of prepared statements MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_131930_15714846.1230466769098" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200812/20 X-Sequence-Number: 6837 ------=_Part_131930_15714846.1230466769098 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline It would be very nice to have a way to get a list of prepared statements. Currently there does not seem to be any: [1] My problem is this: I am using pgsql with PHP, connecting using pg_pconnect(), which will reuse pgsql connections if possible. This means that the pgsql connection returned to my freshly instantiated PHP instance can have "predefined" prepared statements. It would be very nice for performance if I were able to reuse those, however there is no way to know what prepared statements are defined, since there is no pgsql interface to list them. In fact, I am currently prefixing all my prepared query names with a per-session random string to avoid name clashes from previous sessions. The only way to test if a prepared statement with a given name exists seems to be to try to define a new one with the same name. If this gives an error then there exist a statement with that name, but I don't think you can tell whether it is the same actual query as the new one you wanted to define. M. Bastin suggests in [2] to just keep a list in the client app. In my case this would mean modifying PHP to keep the list together with its pool of connections. I guess one could modify PHP, but it seems better and simpler to just modify pgsql to return the list (the pgsql connection presumably already keeps the list); that would fix the problem also for other programming languages using persistent pgsql connections. I don't know what the interface should be; a possibly ignorant suggestion is implementing a build-in stored procedure such that "SELECT * FROM _prepared_statement_list() WHERE name LIKE 'a%'" could return a table of (name TEXT, query TEXT) rows? Another possibility would be using something like "\d" in the psql client (however this is implemented in pgsql), but the IMO the stored procedure approach is better, as -You can use SELECT and WHERE clause to filter the result. -The query will be directly available to for example PHP, without having to add a new postgresql function to access it. If fx PHP really wants such a function, they can implement it by just executing such a query. I am not a pgsql hacker, so I am probably not going to implement this myself. But it would be nice if the pgsql project added it to the pgsql TODO list. :) [1] http://archives.postgresql.org/pgsql-novice/2004-07/msg00089.php [2] http://archives.postgresql.org/pgsql-novice/2004-07/msg00090.php Regards, Thue ------=_Part_131930_15714846.1230466769098 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline It would be very nice to have a way to get a list of prepared statements. Currently there does not seem to be any: [1]

My problem is this: I am using pgsql with PHP, connecting using pg_pconnect(), which will reuse pgsql connections if possible. This means that the pgsql connection returned to my freshly instantiated PHP instance can have "predefined" prepared statements. It would be very nice for performance if I were able to reuse those, however there is no way to know what prepared statements are defined, since there is no pgsql interface to list them. In fact, I am currently prefixing all my prepared query names with a per-session random string to avoid name clashes from previous sessions.

The only way to test if a prepared statement with a given name exists seems to be to try to define a new one with the same name. If this gives an error then there exist a statement with that name, but I don't think you can tell whether it is the same actual query as the new one you wanted to define.

M. Bastin suggests in [2] to just keep a list in the client app. In my case this would mean modifying PHP to keep the list together with its pool of connections. I guess one could modify PHP, but it seems better and simpler to just modify pgsql to return the list (the pgsql connection presumably already keeps the list); that would fix the problem also for other programming languages using persistent pgsql connections.

I don't know what the interface should be; a possibly ignorant suggestion is implementing a build-in stored procedure such that "SELECT * FROM _prepared_statement_list() WHERE name LIKE 'a%'" could return a table of (name TEXT, query TEXT) rows?
Another possibility would be using something like "\d" in the psql client (however this is implemented in pgsql), but the IMO the stored procedure approach is better, as
-You can use SELECT and WHERE clause to filter the result.
-The query will be directly available to for example PHP, without having to add a new postgresql function to access it. If fx PHP really wants such a function, they can implement it by just executing such a query.

I am not a pgsql hacker, so I am probably not going to implement this myself. But it would be nice if the pgsql project added it to the pgsql TODO list. :)

[1] http://archives.postgresql.org/pgsql-novice/2004-07/msg00089.php
[2] http://archives.postgresql.org/pgsql-novice/2004-07/msg00090.php

Regards, Thue ------=_Part_131930_15714846.1230466769098--