Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change start value of sequence in Postgres

I have a table which was populated with data from another environment. When I try to create a new entry it tells me:

ERROR: duplicate key value violates unique constraint "chart_of_account_dimension_config_pkey"
Detail: Key (id)=(1) already exists.

I tried resetting the starting value of the sequence to an higher value by:

select setval(chart_of_account_dimension_id_seq1, 2810, true)

But it tells me

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

column "chart_of_account_dimension_config_id_seq1" does not exist

I tried to run following query, and actually there is no such sequence.
But dBeaver tells me such a sequence exists.

>Solution :

If the query parser sees an identifier like that in that place it tries to treat it as a column.

So you need to do:

select setval('chart_of_account_dimension_id_seq1'::regclass, 2810, true)

That will look up the text name of the sequence and give its underlying identifier.

If you check the output of \dt you should see a similar thing with the DEFAULT for the column using it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading