Skip to content

Instantly share code, notes, and snippets.

@robbkidd
Created July 28, 2012 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robbkidd/3194119 to your computer and use it in GitHub Desktop.
Save robbkidd/3194119 to your computer and use it in GitHub Desktop.
Renaming a Postgres sequence used by multiple tables.
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