Skip site navigation (1) Skip section navigation (2)

Re: alter table schema, default sequences stay the same

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: alter table schema, default sequences stay the same
Date: 2010-06-29 13:24:53
Message-ID: 20100629132453.GD11893@a-kretschmer.de (view raw or flat)
Thread:
Lists: pgsql-general
In response to Scott Marlowe :
> On Tue, Jun 29, 2010 at 8:20 AM, A. Kretschmer
> <andreas(dot)kretschmer(at)schollglas(dot)com> wrote:
> >
> >
> > Just for info: works well with 8.4:
> 
> Works in 8.3.9 on ubuntu 9.10...
> 

I think, this is the problem:
You have created the table first and later the sequence, like this:


test=# create table public.s (i int);
CREATE TABLE
test=*# create sequence my_seq;
CREATE SEQUENCE
test=*# alter table s alter column i set default nextval('my_seq');
ALTER TABLE
test=*# create schema bla;
CREATE SCHEMA
test=*# alter table s set schema bla;
ALTER TABLE
test=*# \d bla.s
                     Table "bla.s"
 Column |  Type   |              Modifiers
--------+---------+-------------------------------------
 i      | integer | default nextval('my_seq'::regclass)


You have now a table in schema bla and the sequence still in public. To
avoid that you have to alter the sequence too:

test=# create table public.s (i int);
CREATE TABLE
test=*# create sequence my_seq;
CREATE SEQUENCE
test=*# alter table s alter column i set default nextval('my_seq');
ALTER TABLE
test=*# alter sequence my_seq owned by s.i;
ALTER SEQUENCE
test=*# create schema bla;
CREATE SCHEMA
test=*# alter table s set schema bla;
ALTER TABLE
test=*# \d bla.s
                       Table "bla.s"
 Column |  Type   |                Modifiers
--------+---------+-----------------------------------------
 i      | integer | default nextval('bla.my_seq'::regclass)


But i'm not sure if 'alter sequence owned ...' available in 8.2.



Regards, Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431  2EB0 389D 1DC2 3172 0C99

In response to

Responses

pgsql-general by date

Next:From: Joshua TolleyDate: 2010-06-29 13:27:37
Subject: Re: pgpool
Previous:From: Sim ZacksDate: 2010-06-29 13:21:49
Subject: Re: alter table schema, default sequences stay the same

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group