Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fLkft-0000dN-BF for pgsql-general@arkaria.postgresql.org; Thu, 24 May 2018 07:28:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fLkfr-0000O9-Hc for pgsql-general@arkaria.postgresql.org; Thu, 24 May 2018 07:28:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fLkfr-0000Nz-9S for pgsql-general@lists.postgresql.org; Thu, 24 May 2018 07:28:35 +0000 Received: from [195.159.176.226] (helo=blaine.gmane.org) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fLkfj-0006nL-Kg for pgsql-general@postgresql.org; Thu, 24 May 2018 07:28:34 +0000 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1fLkdZ-0002Aa-Rl for pgsql-general@postgresql.org; Thu, 24 May 2018 09:26:13 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-general@postgresql.org From: Lele Gaifax Subject: Parameter placeholders, $n vs ? Date: Thu, 24 May 2018 09:28:15 +0200 Organization: Nautilus Entertainments Lines: 49 Message-ID: <87o9h5bjhs.fsf@metapensiero.it> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@blaine.gmane.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cancel-Lock: sha1:ctdiwdcWJIQqqL+++RvPneXfCNc= X-Host-Lookup-Failed: Reverse DNS lookup failed for 195.159.176.226 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi all, while improving the technical documentation of my current project, I hit a SQL statement that triggered a bug in my pg_query[1] based prettifier. The statement in question was using '?' as param placeholders instead of the '$n' style I'm used to: to my surprise the parser (pg_query uses the nice standalone packaging of the PG parser provided by libpg_query[2]) accepted it without problems, although emitting an AST that the prettifier was not able to cope with. Briefly: $ diff -u <(echo 'SELECT * FROM foo WHERE bar = $1' | pgpp -t) \ <(echo 'SELECT * FROM foo WHERE bar = ?' | pgpp -t) --- /dev/fd/63 2018-05-24 09:13:40.877301119 +0200 +++ /dev/fd/62 2018-05-24 09:13:40.877301119 +0200 @@ -56,8 +56,7 @@ ], "rexpr": { "ParamRef": { - "location": 30, - "number": 1 + "location": 30 } } } While the fix to pg_query was trivial, to satisfy my own curiosity I looked around to get evidence of whether the '?' style is officially accepted or what. The ParamRef documentation[3] does not mention that the "number" may be "missing", and given that '?' is very difficult to search I failed to find a definitive answer. So the questions: is the '?' style placeholder a supported variant? and if so, should the ParamRef doc tell something about that? Thanks in advance, ciao, lele. [1] https://github.com/lelit/pg_query/ [2] https://github.com/lfittl/libpg_query [3] https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/include/nodes/parsenodes.h;h=6390f7e8c129e84607e1bb3c56ddd8578115f298;hb=HEAD#l243 -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. lele@metapensiero.it | -- Fortunato Depero, 1929.