Search Postgresql Archives

Re: alter table schema, default sequences stay the same

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In response to Scott Marlowe :
> On Tue, Jun 29, 2010 at 8:20 AM, A. Kretschmer
> <andreas.kretschmer@xxxxxxxxxxxxxx> 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

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux