0 votes
1 view
in SQL by (22.4k points)

I would like to force the auto increment field of a table to some value, I tried with this:

ALTER TABLE product AUTO_INCREMENT = 1453

AND

ALTER SEQUENCE product  RESTART WITH 1453;

ERROR:  relation "your_sequence_name" does not exist

I'm new to postgres :(

I have a table product with Id and name field

1 Answer

0 votes
by (40.3k points)

If you have created the table product with associated id column, then the sequence isn't merely known as product, however rather product_id_seq (that is, ${table}_${column}_seq).

This is the ALTER SEQUENCE command that you need:

ALTER SEQUENCE product_id_seq RESTART WITH 1453

 In PSQL, you can see the sequences in the database by using the \ds command. 

Note: If you are doing \d product and observe the default constraint for your column, the nextval(...) decision call can specify the sequence name too.

If you want to learn sql commands visit these SQL commands cheat sheet.

Related questions

+2 votes
1 answer
asked Jun 24, 2019 in SQL by Sammy (47.8k points)
0 votes
1 answer
asked Jul 31, 2019 in SQL by Tech4ever (22.4k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...