File tree 2 files changed +28
-1
lines changed
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
7
7
warrant a full blog post. These are mostly things I learn by pairing with
8
8
smart people at [ Hashrocket] ( http://hashrocket.com/ ) .
9
9
10
- _ 375 TILs and counting..._
10
+ _ 376 TILs and counting..._
11
11
12
12
---
13
13
@@ -195,6 +195,7 @@ _375 TILs and counting..._
195
195
- [ Max Identifier Length Is 63 Bytes] ( postgres/max-identifier-length-is-63-bytes.md )
196
196
- [ pg Prefix Is Reserved For System Schemas] ( postgres/pg-prefix-is-reserved-for-system-schemas.md )
197
197
- [ Pretty Print Data Sizes] ( postgres/pretty-print-data-sizes.md )
198
+ - [ Renaming A Sequence] ( postgres/renaming-a-sequence.md )
198
199
- [ Renaming A Table] ( postgres/renaming-a-table.md )
199
200
- [ Restart A Sequence] ( postgres/restart-a-sequence.md )
200
201
- [ Restarting Sequences When Truncating Tables] ( postgres/restarting-sequences-when-truncating-tables.md )
Original file line number Diff line number Diff line change
1
+ # Renaming A Sequence
2
+
3
+ If a table is created with a ` serial ` type column, then a sequence is also
4
+ created with a name based on the name of the table.
5
+
6
+ ``` sql
7
+ > \d
8
+ List of relations
9
+ Schema | Name | Type | Owner
10
+ -- ------+-----------------+----------+------------
11
+ public | accounts | table | jbranchaud
12
+ public | accounts_id_seq | sequence | jbranchaud
13
+ ```
14
+
15
+ In [ Renaming A Table] ( renaming-a-table.md ) , I showed how a table can be
16
+ renamed in PostgreSQL. This will not, however, rename associated sequences.
17
+ To maintain naming consistency, you may want to also rename sequences when
18
+ renaming tables. This can be done with a query like the following:
19
+
20
+ ``` sql
21
+ > alter sequence accounts_id_seq rename to users_id_seq;
22
+ ```
23
+
24
+ See the [ `alter
25
+ sequence`] ( http://www.postgresql.org/docs/current/static/sql-altersequence.html )
26
+ docs for more details.
You can’t perform that action at this time.
0 commit comments