Created
July 28, 2012 17:30
-
-
Save robbkidd/3194119 to your computer and use it in GitHub Desktop.
Renaming a Postgres sequence used by multiple tables.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testy=# CREATE SEQUENCE common_fruit_id_seq; | |
CREATE SEQUENCE | |
testy=# | |
testy=# CREATE TABLE apples ( | |
testy(# id INT4 DEFAULT nextval('common_fruit_id_seq') NOT NULL, | |
testy(# price NUMERIC | |
testy(# ); | |
CREATE TABLE | |
testy=# | |
testy=# CREATE TABLE oranges ( | |
testy(# id INT4 DEFAULT nextval('common_fruit_id_seq') NOT NULL, | |
testy(# weight NUMERIC | |
testy(# ); | |
CREATE TABLE | |
testy=# \d oranges | |
Table "public.oranges" | |
Column | Type | Modifiers | |
--------+---------+----------------------------------------------------------- | |
id | integer | not null default nextval('common_fruit_id_seq'::regclass) | |
weight | numeric | | |
testy=# ALTER TABLE "common_fruit_id_seq" RENAME TO "all_the_fruit_id_seq"; | |
ALTER TABLE | |
testy=# \d oranges | |
Table "public.oranges" | |
Column | Type | Modifiers | |
--------+---------+------------------------------------------------------------ | |
id | integer | not null default nextval('all_the_fruit_id_seq'::regclass) | |
weight | numeric | | |
testy=# \d apples | |
Table "public.apples" | |
Column | Type | Modifiers | |
--------+---------+------------------------------------------------------------ | |
id | integer | not null default nextval('all_the_fruit_id_seq'::regclass) | |
price | numeric | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment