pgsql: pg_dump: Fix array literals in fetchAttributeStats().

From: Nathan Bossart <nathan(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: pg_dump: Fix array literals in fetchAttributeStats().
Date: 2025-05-20 21:31:31
Message-ID: E1uHUYd-0000m5-0C@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: 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(dot)emaj(at)free(dot)fr>
Author: Jian He <jian(dot)universality(at)gmail(dot)com>
Co-authored-by: Nathan Bossart <nathandbossart(at)gmail(dot)com>
Co-authored-by: Stepan Neretin <slpmcf(at)gmail(dot)com>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2025-05-21 01:25:06 pgsql: Fix regression with location calculation of nested statements
Previous Message Tom Lane 2025-05-20 14:55:26 pgsql: Fix back-patching of memset_s() fixes.