Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 836E862E9C1 for ; Mon, 5 Oct 2009 18:46:12 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 36288-08 for ; Mon, 5 Oct 2009 21:46:04 +0000 (UTC) X-Greylist: delayed 00:10:08.995678 by SQLgrey-1.7.6 Received: from www.bandbreiter.net (h1057542.serverkompetenz.net [85.214.72.161]) by mail.postgresql.org (Postfix) with ESMTP id 9FF2B6336C4 for ; Mon, 5 Oct 2009 18:46:04 -0300 (ADT) Received: from [192.168.34.189] (95-88-199-142-dynip.superkabel.de [95.88.199.142]) by www.bandbreiter.net (Postfix) with ESMTPA id 65AE533944F for ; Mon, 5 Oct 2009 23:35:52 +0200 (CEST) Message-ID: <4ACA6668.2000701@gmx.de> Date: Mon, 05 Oct 2009 23:34:32 +0200 From: Marco Dieckhoff User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.23) Gecko/20090812 Lightning/0.9 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 MIME-Version: 1.0 To: pgsql-php@postgresql.org Subject: checking select query syntax and semantics via php without executing Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.74 tagged_above=-10 required=5 tests=BAYES_20=-0.74 X-Spam-Level: X-Archive-Number: 200910/1 X-Sequence-Number: 4080 Hi there! Is it possible in PHP to give a sql (select) query to Postgres via pg_* so that it is NOT executed but merely checked for syntax including correct, existing field and table names, and data types? I'm working on a system where users may assemble their own query in a construction kit, and want that to be checked, so that they don't e.g. compare UUID "<" datetime or something like this. If I try to execute the generated query, bad queries are instantly found by pg_query. But good ones are fully executed, which can take a long time depending on joins and aggregations. It seems that pg_prepare doesn't return errors on bad queries, pg_last_error() is empty. The asynchronous pg_send_query (and pg_cancel_query) seem not to return any errors, either. I tried with three queries: "SELECT * FROM tableok" "SELECT nonexistingfield FROM nonexistingtable" "SELECT complete bad / sql query FROM nonsense" Any ideas?