Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/bin/pg_dump/pg_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -9556,6 +9556,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
"a.attalign,\n"
"a.attislocal,\n"
"pg_catalog.format_type(t.oid, a.atttypmod) AS atttypname,\n"
"pg_catalog.array_to_string(e.attoptions, ',') AS attencoding,\n"
"array_to_string(a.attoptions, ', ') AS attoptions,\n"
"CASE WHEN a.attcollation <> t.typcollation "
"THEN a.attcollation ELSE 0 END AS attcollation,\n"
Expand Down Expand Up @@ -9601,6 +9602,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
"JOIN pg_catalog.pg_attribute a ON (src.tbloid = a.attrelid) "
"LEFT JOIN pg_catalog.pg_type t "
"ON (a.atttypid = t.oid)\n"
"LEFT JOIN pg_catalog.pg_attribute_encoding e "
"ON (e.attrelid = a.attrelid AND e.attnum = a.attnum) "
"WHERE a.attnum > 0::pg_catalog.int2\n"
"ORDER BY a.attrelid, a.attnum",
tbloids->data);
Expand Down Expand Up @@ -9629,6 +9632,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
i_attfdwoptions = PQfnumber(res, "attfdwoptions");
i_attmissingval = PQfnumber(res, "attmissingval");
i_atthasdef = PQfnumber(res, "atthasdef");
i_attencoding = PQfnumber(res, "attencoding");

/* Within the next loop, we'll accumulate OIDs of tables with defaults */
resetPQExpBuffer(tbloids);
Expand Down Expand Up @@ -9669,9 +9673,6 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
pg_fatal("unexpected column data for table \"%s\"",
tbinfo->dobj.name);

i_attencoding = PQfnumber(res, "attencoding");

tbinfo->attencoding = (char **) pg_malloc(ntups * sizeof(char *));
/* Save data for this table */
tbinfo->numatts = numatts;
tbinfo->attnames = (char **) pg_malloc(numatts * sizeof(char *));
Expand All @@ -9693,6 +9694,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
tbinfo->notnull = (bool *) pg_malloc(numatts * sizeof(bool));
tbinfo->inhNotNull = (bool *) pg_malloc(numatts * sizeof(bool));
tbinfo->attrdefs = (AttrDefInfo **) pg_malloc(numatts * sizeof(AttrDefInfo *));
tbinfo->attencoding = (char **) pg_malloc(numatts * sizeof(char *));
hasdefaults = false;

for (int j = 0; j < numatts; j++, r++)
Expand Down Expand Up @@ -9725,8 +9727,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
tbinfo->inhNotNull[j] = false;

/* column storage attributes */
if (!PQgetisnull(res, j, i_attencoding))
tbinfo->attencoding[j] = pg_strdup(PQgetvalue(res, j, i_attencoding));
if (!PQgetisnull(res, r, i_attencoding))
tbinfo->attencoding[j] = pg_strdup(PQgetvalue(res, r, i_attencoding));
else
tbinfo->attencoding[j] = NULL;
}
Expand Down
17 changes: 17 additions & 0 deletions src/bin/pg_dump/t/003_pg_dump_with_server.pl
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,21 @@
[ "pg_dump", '-p', $port, '-a', '--include-foreign-data=s2', 'postgres' ],
"dump foreign server with no tables");

# Dump both tables together so their column encodings must be read from
# different rows of the same result set.
$node->safe_psql(
'postgres', q{
CREATE TABLE aoco_first
(i int ENCODING (compresstype=zlib, compresslevel=1))
USING ao_column DISTRIBUTED BY (i);
CREATE TABLE aoco_second
(i int ENCODING (compresstype=zlib, compresslevel=7))
USING ao_column DISTRIBUTED BY (i);
});

command_like(
[ 'pg_dump', '-p', $port, '--schema-only', '--table=aoco_*', 'postgres' ],
qr/^CREATE TABLE public\.aoco_second \([^;]*\bCOLUMN i ENCODING \([^)\n]*\bcompresslevel=7\b/m,
'schema dump preserves the second AOCO table column encoding');

done_testing();
Loading