Jernej K
Jernej K

Reputation: 1684

Change sequence name in postgreSQL

I would like to change the name of my sequence I use. I tried those two options and failed:

ALTER TABLE PLAYER RENAME id_seq_player TO player_id_seq;

and

ALTER SEQUENCE id_seq_player RENAME TO player_id_seq;

I looked at the official documentation and from there I created those two SQL, but none of them worked. The first solution resulted in a SQL error and the second had a time out.

Here is the SQL error I get:

ERROR:  column "id_seq_player" does not exist

********** Error **********

* UPDATE *

Seems like the second SQL statement did the job. Since I have to forward the port, maybe it was an issue with the connection or OpenShift. But now I retried several times to verify and it works.

ALTER SEQUENCE id_seq_player RENAME TO player_id_seq; /* Works */

Upvotes: 35

Views: 27719

Answers (3)

Shubham Batra
Shubham Batra

Reputation: 2375

Try this:

ALTER TABLE id_seq_player RENAME TO player_id_seq;

Upvotes: 6

Anthony Drogon
Anthony Drogon

Reputation: 1864

ALTER SEQUENCE id_seq_player RENAME TO player_id_seq;

is correct. You might want to add the schema name as well to ensure you are altering the correct one, but this should most likely work.

If it timeouts, you might have another process that is locking your sequence. Is there a way for you to turn off all the other database users, or is it too critical to do so?

Upvotes: 70

Juan Carlos Oropeza
Juan Carlos Oropeza

Reputation: 48197

Dont know the command line but you can change it on the pgAdmin

I just add 1 to my sequence and change it back.

enter image description here

Upvotes: 0

Related Questions