Serial Data Type Failure

Started by David Hartwigover 27 years ago3 messages
#1David Hartwig
daveh@insightdist.com

Tom,

The following came from the most recient snapshot. I know your away
for a few days. I will give it a look-see if I get time this weekend

CREATE TABLE foo (
id serial primary key,
name varchar(32)
);
NOTICE: CREATE TABLE will create implicit sequence foo_id_seq for
SERIAL column foo.id
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index foo_pkey
for table foo
CREATE
-- This is good. Thanks.

CREATE TABLE bar (
id serial,
name varchar(32)
);
NOTICE: CREATE TABLE will create implicit sequence bar_id_key for
SERIAL column bar.id
NOTICE: CREATE TABLE/UNIQUE will create implicit index bar_id_key for
table bar
ERROR: Cannot create index: 'bar_id_key' already exists
-- This is bad. Sorry.

#2Thomas G. Lockhart
lockhart@alumni.caltech.edu
In reply to: David Hartwig (#1)
Re: Serial Data Type Failure

The following came from the most recient snapshot.
CREATE TABLE bar (
id serial,
name varchar(32)
);
NOTICE: CREATE TABLE will create implicit sequence bar_id_key for
SERIAL column bar.id
NOTICE: CREATE TABLE/UNIQUE will create implicit index bar_id_key for
table bar
ERROR: Cannot create index: 'bar_id_key' already exists
-- This is bad. Sorry.

OK, will look at it if you haven't fixed it already...

- Tom

#3Thomas G. Lockhart
lockhart@alumni.caltech.edu
In reply to: David Hartwig (#1)
1 attachment(s)
Re: [HACKERS] Re: Serial Data Type Failure

ERROR: Cannot create index: 'bar_id_key' already exists
-- This is bad. Sorry.

postgres=> CREATE TABLE bar (
postgres-> id serial,
postgres-> name varchar(32)
postgres-> );
NOTICE: CREATE TABLE will create implicit sequence bar_id_seq for
SERIAL column bar.id
NOTICE: CREATE TABLE/UNIQUE will create implicit index bar_id_key for
table bar
CREATE

I hadn't noticed that there was a positional dependency in the code I
had moved around to implement the SERIAL PRIMARY KEY feature. Sorry
about that.

Patch enclosed. Will commit to source tree soon...

- Tom

Attachments:

analyze.c.patchtext/plain; charset=us-ascii; name=analyze.c.patchDownload
*** analyze.c.orig	Wed Sep 16 14:59:22 1998
--- analyze.c	Mon Sep 21 05:18:07 1998
***************
*** 517,528 ****
  
  				if (column->is_sequence)
  				{
! 					char	   *cstring;
  					CreateSeqStmt *sequence;
  
  					constraint = makeNode(Constraint);
  					constraint->contype = CONSTR_DEFAULT;
! 					constraint->name = makeTableName(stmt->relname, column->colname, "seq", NULL);
  					cstring = palloc(9 + strlen(constraint->name) + 2 + 1);
  					strcpy(cstring, "nextval('");
  					strcat(cstring, constraint->name);
--- 517,529 ----
  
  				if (column->is_sequence)
  				{
! 					char		  *sname;
! 					char		  *cstring;
  					CreateSeqStmt *sequence;
  
  					constraint = makeNode(Constraint);
  					constraint->contype = CONSTR_DEFAULT;
! 					constraint->name = sname = makeTableName(stmt->relname, column->colname, "seq", NULL);
  					cstring = palloc(9 + strlen(constraint->name) + 2 + 1);
  					strcpy(cstring, "nextval('");
  					strcat(cstring, constraint->name);
***************
*** 551,557 ****
  					}
  
  					sequence = makeNode(CreateSeqStmt);
! 					sequence->seqname = pstrdup(constraint->name);
  					sequence->options = NIL;
  
  					elog(NOTICE, "CREATE TABLE will create implicit sequence %s for SERIAL column %s.%s",
--- 552,558 ----
  					}
  
  					sequence = makeNode(CreateSeqStmt);
! 					sequence->seqname = pstrdup(sname);
  					sequence->options = NIL;
  
  					elog(NOTICE, "CREATE TABLE will create implicit sequence %s for SERIAL column %s.%s",