1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Add pg_get_serial_sequence() function, and cause pg_dump to use it.

This eliminates the assumption that a serial column's sequence will
have the same name on reload that it was given in the original database.

Christopher Kings-Lynne
This commit is contained in:
Tom Lane
2004-06-25 17:20:29 +00:00
parent ef2880263c
commit a0e842d81b
6 changed files with 185 additions and 29 deletions

View File

@@ -12,7 +12,7 @@
* by PostgreSQL
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.376 2004/06/21 13:36:41 tgl Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.377 2004/06/25 17:20:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -7319,9 +7319,27 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
if (!schemaOnly)
{
TableInfo *owning_tab;
resetPQExpBuffer(query);
appendPQExpBuffer(query, "SELECT pg_catalog.setval(");
appendStringLiteral(query, fmtId(tbinfo->dobj.name), true);
/*
* If this is a SERIAL sequence, then use the pg_get_serial_sequence
* function to avoid hard-coding the sequence name. Note that this
* implicitly assumes that the sequence and its owning table are in
* the same schema, because we don't schema-qualify the reference.
*/
if (OidIsValid(tbinfo->owning_tab) &&
(owning_tab = findTableByOid(tbinfo->owning_tab)) != NULL)
{
appendPQExpBuffer(query, "pg_catalog.pg_get_serial_sequence(");
appendStringLiteral(query, fmtId(owning_tab->dobj.name), true);
appendPQExpBuffer(query, ", ");
appendStringLiteral(query, owning_tab->attnames[tbinfo->owning_col-1], true);
appendPQExpBuffer(query, ")");
}
else
appendStringLiteral(query, fmtId(tbinfo->dobj.name), true);
appendPQExpBuffer(query, ", %s, %s);\n",
last, (called ? "true" : "false"));