pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Raymond Mitchell <rmitchell@indyme.com>
To: pgsql-admin@postgresql.org
Cc: Raymond Mitchell <rmitchell@indyme.com>
Subject: pg_dump'ing sequences that are part of a primary key
Date: Wed, 18 Sep 2002 16:33:11 -0700
Message-ID: <64D857A8547DD611AE9B00304821BA3114D84F@INDYMEMAIL.INDY.COM> (raw)

Hi all,

When I restore a database from the output of pg_dump, some sequences aren't
restored correctly.  Specifically, sequences that are associated with a
column that is part of a mult-column primary key aren't restored.  This is
the output of pg_dump (run with the -d flag to force inserts) for such a
sequence.  These statement appear in the order they are produced by pg_dump
with intervening statements removed:


CREATE SEQUENCE "next_div_id" start 1 increment 1 maxvalue 2147483647
minvalue 1 cache 1;

CREATE TABLE "division_tbl" (
        "division_name" character varying(25) NOT NULL,
        "division_id" integer,
        "level_id" integer NOT NULL,
        Constraint "division_pkey" Primary Key ("division_name", "level_id")
);

INSERT INTO "division_tbl" VALUES ('TST',1,1);
INSERT INTO "division_tbl" VALUES ('11',2,2);
INSERT INTO "division_tbl" VALUES ('500',3,3);
INSERT INTO "division_tbl" VALUES ('11',4,4);
INSERT INTO "division_tbl" VALUES ('12',5,2);

CREATE TRIGGER "next_divsion_id" BEFORE INSERT OR UPDATE ON "division_tbl"
FOR EACH ROW EXECUTE PROCEDURE "autoinc" ('division_id', 'next_div_id');

SELECT setval ('"next_div_id"', 1, true);


Notice that the table being dumped contains five values (hence the five
INSERT statements) with division_id's 1 through 5, but the next_div_id is
being set to the starting value of 1 instead of 5.  Also note that the
Primary Key for the division_tbl table is set to both the division_name and
division_id columns.  When a similar table whose Primary Key is ONLY the
sequenced column "division_id" is dumped, the next_div_id is correctly
dumped as 5.

Shouldn't pg_dump set the sequence value to 5, regardless of whether the
referenced column is part of a multi-part primary key?

Thanks,
Ray



Message-ID: <64D857A8547DD611AE9B00304821BA3114D84F@INDYMEMAIL.INDY.COM>
Permalink:  ../64D857A8547DD611AE9B00304821BA3114D84F@INDYMEMAIL.INDY.COM/
Also on:    postgresql.org/message-id/64D857A8547DD611AE9B00304821BA3114D84F@INDYMEMAIL.INDY.COM

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: rmitchell@indyme.com
  Subject: Re: pg_dump'ing sequences that are part of a primary key
  In-Reply-To: <64D857A8547DD611AE9B00304821BA3114D84F@INDYMEMAIL.INDY.COM>
  References: <64D857A8547DD611AE9B00304821BA3114D84F@INDYMEMAIL.INDY.COM>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox