pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedRenaming a sequence?
3+ messages / 2 participants
[nested] [flat]
* Renaming a sequence?
@ 2006-03-25 03:22 ogjunk-pgjedan@yahoo.com
0 siblings, 1 reply; 3+ messages in thread
From: ogjunk-pgjedan@yahoo.com @ 2006-03-25 03:22 UTC (permalink / raw)
To: pgsql-admin
Hi,
I just renamed some of my tables, but I now have sequences with older names.
I followed info from http://www.postgresql.org/docs/current/static/sql-altersequence.html :
"Some variants of ALTER TABLE can be used with sequences as well; for example, to rename a sequence use ALTER TABLE RENAME"
So this is what I did:
ALTER TABLE topic_id_seq RENAME TO watchlist_id_seq;
That *appeared* to work, but I still see the old sequence name:
mydb => \d watchlist
Table "public.watchlist"
Column | Type | Modifiers
--------------+-------------------------------+-------------------------------------------------------
id | integer | not null default nextval('public.topic_id_seq'::text)
...
Indexes:
"pk_topic_id" PRIMARY KEY, btree (id)
It looks like my sequence WAS renamed, but my table's PK points to the old sequence name, which is not supposed to exist any more. Is there any way to change this without killing the sequence?
Thanks,
Otis
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Renaming a sequence?
@ 2006-03-25 17:49 Andy Shellam <andy.shellam@mailnetwork.co.uk>
parent: ogjunk-pgjedan@yahoo.com
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shellam @ 2006-03-25 17:49 UTC (permalink / raw)
To: ogjunk-pgjedan@yahoo.com; pgsql-admin; +Cc: pgsql-admin
You also need to alter your column's default value to point to your new
sequence (nextval('public.watchlist_id_seq'::text)).
I'm not certain of the SQL to do this but must be along the order of "ALTER
COLUMN <tablename>.<column name> DEFAULT
nextval('public.watchlist_id_seq'::text)" or something similar.
Andy
-----Original Message-----
From: pgsql-admin-owner@postgresql.org
[mailto:pgsql-admin-owner@postgresql.org] On Behalf Of
ogjunk-pgjedan@yahoo.com
Sent: Saturday, 25 March, 2006 3:23 am
To: pgsql-admin@postgresql.org
Subject: [ADMIN] Renaming a sequence?
Hi,
I just renamed some of my tables, but I now have sequences with older names.
I followed info from
http://www.postgresql.org/docs/current/static/sql-altersequence.html :
"Some variants of ALTER TABLE can be used with sequences as well; for
example, to rename a sequence use ALTER TABLE RENAME"
So this is what I did:
ALTER TABLE topic_id_seq RENAME TO watchlist_id_seq;
That *appeared* to work, but I still see the old sequence name:
mydb => \d watchlist
Table "public.watchlist"
Column | Type | Modifiers
--------------+-------------------------------+-----------------------------
--------------------------
id | integer | not null default
nextval('public.topic_id_seq'::text)
...
Indexes:
"pk_topic_id" PRIMARY KEY, btree (id)
It looks like my sequence WAS renamed, but my table's PK points to the old
sequence name, which is not supposed to exist any more. Is there any way to
change this without killing the sequence?
Thanks,
Otis
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly
!DSPAM:14,4424b7b935047329715045!
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Renaming a sequence?
@ 2006-03-25 22:54 ogjunk-pgjedan@yahoo.com
parent: Andy Shellam <andy.shellam@mailnetwork.co.uk>
0 siblings, 0 replies; 3+ messages in thread
From: ogjunk-pgjedan@yahoo.com @ 2006-03-25 22:54 UTC (permalink / raw)
To: pgsql-admin
Thanks Andy, this was it:
ALTER TABLE watchlist ALTER COLUMN id SET DEFAULT nextval('public.watchlist_id_seq'::text);
Otis
----- Original Message ----
From: Andy Shellam <andy.shellam@mailnetwork.co.uk>
To: ogjunk-pgjedan@yahoo.com; pgsql-admin@postgresql.org
Cc: pgsql-admin@postgresql.org
Sent: Saturday, March 25, 2006 12:49:45 PM
Subject: Re: [ADMIN] Renaming a sequence?
You also need to alter your column's default value to point to your new
sequence (nextval('public.watchlist_id_seq'::text)).
I'm not certain of the SQL to do this but must be along the order of "ALTER
COLUMN <tablename>.<column name> DEFAULT
nextval('public.watchlist_id_seq'::text)" or something similar.
Andy
-----Original Message-----
From: pgsql-admin-owner@postgresql.org
[mailto:pgsql-admin-owner@postgresql.org] On Behalf Of
ogjunk-pgjedan@yahoo.com
Sent: Saturday, 25 March, 2006 3:23 am
To: pgsql-admin@postgresql.org
Subject: [ADMIN] Renaming a sequence?
Hi,
I just renamed some of my tables, but I now have sequences with older names.
I followed info from
http://www.postgresql.org/docs/current/static/sql-altersequence.html :
"Some variants of ALTER TABLE can be used with sequences as well; for
example, to rename a sequence use ALTER TABLE RENAME"
So this is what I did:
ALTER TABLE topic_id_seq RENAME TO watchlist_id_seq;
That *appeared* to work, but I still see the old sequence name:
mydb => \d watchlist
Table "public.watchlist"
Column | Type | Modifiers
--------------+-------------------------------+-----------------------------
--------------------------
id | integer | not null default
nextval('public.topic_id_seq'::text)
...
Indexes:
"pk_topic_id" PRIMARY KEY, btree (id)
It looks like my sequence WAS renamed, but my table's PK points to the old
sequence name, which is not supposed to exist any more. Is there any way to
change this without killing the sequence?
Thanks,
Otis
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly
!DSPAM:14,4424b7b935047329715045!
---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2006-03-25 22:54 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-03-25 03:22 Renaming a sequence? ogjunk-pgjedan@yahoo.com
2006-03-25 17:49 ` Andy Shellam <andy.shellam@mailnetwork.co.uk>
2006-03-25 22:54 ` ogjunk-pgjedan@yahoo.com
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