pgsql: Add documentation and tests for quote marks in ECPG literal quer

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add documentation and tests for quote marks in ECPG literal quer
Date: 2020-10-22 22:30:10
Message-ID: E1kVj62-0004Pk-5Q@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2020-10-23 01:25:03 pgsql: Sync our copy of the timezone library with IANA release tzcode20
Previous Message Robert Haas 2020-10-22 22:15:26 pgsql: Try to avoid a compiler warning about using fxid uninitialized.