I have user tables and now I want to add one serial column cid:
user:
id | username | email | createdAt
-------------------------------------------------
"uuid" | "abc" | "[email protected]" | '2017-01-01'
"uuid" | "abc" | "[email protected]" | '2017-02-01'
"uuid" | "abc" | "[email protected]" | '2017-03-01'
I want to add a column cid with values like serial but not primary key
id |username| email | createdAt | cid
-------------------------------------------------------
"uuid" | "abc" | "[email protected]" | '2017-01-01' | 1
"uuid" | "abc" | "[email protected]" | '2017-02-01' | 2
"uuid" | "abc" | "[email protected]" | '2017-03-01' | 3
...
What I tried:
alter table user add column cid serial not null;
but it generates:
id |username| email | createdAt | cid
-------------------------------------------------------
"uuid" | "abc" | "[email protected]" | '2017-01-01' | 4
"uuid" | "abc" | "[email protected]" | '2017-02-01' | 7
"uuid" | "abc" | "[email protected]" | '2017-03-01' | 3
....
can I do something like:
alter table user add column cid serial not null order by createdAt
So that it can generate the expected result which is cid sequential values with order by createdAt?