Re: yowch: dumpRules(): SELECT failed for table website.

From: "Ross J(dot) Reedstrom" <reedstrm(at)wallace(dot)ece(dot)rice(dot)edu>
To: Alfred Perlstein <bright(at)wintelcom(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: yowch: dumpRules(): SELECT failed for table website.
Date: 2000-05-24 14:59:39
Message-ID: 20000524095939.C14883@rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, May 24, 2000 at 03:33:39AM -0700, Alfred Perlstein wrote:
> I'm wondering if there's a way to get a unique value into a table?
>
> this caused some problems:
>
> CREATE TABLE "data" (
> "d" varchar(256) PRIMARY KEY,
> "d_id" serial
> );
>
> because after I reloaded the table from:
>
> insert into data select * from data_backup;
>
> then tried to insert into 'data' using only values for 'd' then it barfed
> because it was trying to use values from the serial that were already
> in the table.
>
> is there a way around this? using OID doesn't seem right, but seems to
> be the only "safe" way to get a truly unique key to use as a forien key
> that I've seen.
>
> any suggestions?
>

Right, I assume this is after you recreated the table? That created a new
sequence behind the serial for d_id, which needs to be updated after you
insert explicit values into the id field. here's my standard fix for that

SELECT setval('data_d_id_seq',max(d_id)) from data;

The name of the sequence is <tablename>_<serial field name>_seq,
trimmed to fit in NAMEDATALEN (default 30). If you created the table
with a different name, that's how the sequence is named (they're not
automatically renamed, or dropped, with their associated table)

I do this whenever I load data into a table manually. Hmm, it might be
possible to setup a trigger (or rule?) to handle the non-default case
(i.e., whenever a serial values is actually provided) and do this
automatically. It'd only need to fire if the inserted/updated value is
greater than currval of the sequence. Hmm...

Ross
--
Ross J. Reedstrom, Ph.D., <reedstrm(at)rice(dot)edu>
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St., Houston, TX 77005

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2000-05-24 15:06:18 Re: setproctitle()
Previous Message The Hermit Hacker 2000-05-24 14:59:01 Re: setproctitle()