pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add documentation and tests for quote marks in ECPG literal quer
Date: Thu, 22 Oct 2020 22:30:10 +0000
Message-ID: <E1kVj62-0004Pk-5Q@gemulon.postgresql.org> (raw)

Add documentation and tests for quote marks in ECPG literal queries.

ECPG's PREPARE ... FROM and EXECUTE IMMEDIATE can optionally take
the target query as a simple literal, rather than the more usual
string-variable reference.  This was previously documented as
being a C string literal, but that's a lie in one critical respect:
you can't write a data double quote as \" in such literals.  That's
because the lexer is in SQL mode at this point, so it'll parse
double-quoted strings as SQL identifiers, within which backslash
is not special, so \" ends the literal.

I looked into making this work as documented, but getting the lexer
to switch behaviors at just the right point is somewhere between
very difficult and impossible.  It's not really worth the trouble,
because these cases are next to useless: if you have a fixed SQL
statement to execute or prepare, you might as well write it as
a direct EXEC SQL, saving the messiness of converting it into
a string literal and gaining the opportunity for compile-time
SQL syntax checking.

Instead, let's just document (and test) the workaround of writing
a double quote as an octal escape (\042) in such cases.

There's no code behavioral change here, so in principle this could
be back-patched, but it's such a niche case I doubt it's worth
the trouble.

Per report from 1250kv.

Discussion: https://postgr.es/m/673825.1603223178@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/c16a1bbcf498f0aa053a3e55008f57d7f67357dd

Modified Files
--------------
doc/src/sgml/ecpg.sgml                             | 59 ++++++++++++++++++++--
src/interfaces/ecpg/preproc/pgc.l                  |  9 +++-
src/interfaces/ecpg/test/expected/sql-execute.c    |  4 +-
.../ecpg/test/expected/sql-execute.stderr          |  2 +-
src/interfaces/ecpg/test/sql/execute.pgc           |  4 +-
5 files changed, 67 insertions(+), 11 deletions(-)



Message-ID: <E1kVj62-0004Pk-5Q@gemulon.postgresql.org>
Permalink:  ../E1kVj62-0004Pk-5Q@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1kVj62-0004Pk-5Q@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Add documentation and tests for quote marks in ECPG literal quer
  In-Reply-To: <E1kVj62-0004Pk-5Q@gemulon.postgresql.org>
  References: <E1kVj62-0004Pk-5Q@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox