39

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 */
2
  • Do you own that sequence? Commented Apr 1, 2016 at 17:37
  • I do. I only use one user and that user created all tables with the corresponding sequences. But I will double check in my logs if there is something weird going on. Commented Apr 1, 2016 at 17:38

3 Answers 3

74
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?

Sign up to request clarification or add additional context in comments.

Comments

6

Try this:

ALTER TABLE id_seq_player RENAME TO player_id_seq;

Comments

0

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

4 Comments

I want the SQL statement, because I have several sequences, where I would like to rename them. And I do not want to do that manually for each of them. I am only using pgAdmin, because that is the only way I can connect to the database since I use Openshift. But thanks, I will keep that in mind.
And the SQL you forwarded basically not renames but creates a new one. I do not like the SQL it uses. I know there is a rename SQL statement I could use.
No. pgAdmin show you the create, But I show you the left side where I right click properties and change the name.
Like I wrote in the second comment, it does remove the current and creates a new one. I do not like that and it is also odd the start value is 1. I will continue to play with this solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.