pgsql: pg_dump: Fix array literals in fetchAttributeStats(). - Mailing list pgsql-committers

From Nathan Bossart
Subject pgsql: pg_dump: Fix array literals in fetchAttributeStats().
Date
Msg-id E1uHUYd-0000m5-0C@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
pg_dump: Fix array literals in fetchAttributeStats().

Presently, fetchAttributeStats() builds array literals by treating
the elements as SQL identifiers.  This is incorrect for a couple of
reasons:

* Array literal content must match the external text representation
  of the array, i.e., what array_out() would return.  One notable
  problem is that double quotes are escaped with "" in identifiers
  but with \" in array literals.  To fix, build the array content
  using the pre-existing appendPGArray() function.

* Array literals must be written as string constants.  A notable
  problem here is that single quotes are escaped via '' in strings
  but are not escaped in the text representation of an array.  To
  fix, append the aforementioned array literal content to the query
  with appendStringLiteralAH().

While at it, modify a test case to use an identifier that would
cause the test to fail without this change.

Oversight in commit 9c02e3a986.

Reported-by: Philippe Beaudoin <pbh.emaj@free.fr>
Author: Jian He <jian.universality@gmail.com>
Co-authored-by: Nathan Bossart <nathandbossart@gmail.com>
Co-authored-by: Stepan Neretin <slpmcf@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Bug: #18923
Discussion: https://postgr.es/m/18923-e79273f87c6bed69%40postgresql.org

Branch
------
master

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

Modified Files
--------------
src/bin/pg_dump/pg_dump.c        | 21 +++++++++++++--------
src/bin/pg_dump/t/002_pg_dump.pl |  6 +++---
2 files changed, 16 insertions(+), 11 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Fix back-patching of memset_s() fixes.
Next
From: Michael Paquier
Date:
Subject: pgsql: Fix regression with location calculation of nested statements