Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change sequence using SQL Query

Tags:

sql

postgresql

I want to change some data in a table with _id_seq suffix with this sql query:

UPDATE user_custom_fields_id_seq SET last_value = 1000;

but I get the following error:

ERROR: cannot change sequence "user_custom_fields_id_seq"

Is there anyway to bypass this error by using just SQL?

like image 268
Leo Avatar asked Jul 23 '17 10:07

Leo


People also ask

How do you change a sequence in SQL?

Sequences objects are created by using the CREATE SEQUENCE statement. Sequences are integer values and can be of any data type that returns an integer. The data type cannot be changed by using the ALTER SEQUENCE statement. To change the data type, drop and create the sequence object.

How do you modify an existing sequence?

Use the ALTER SEQUENCE statement to change the increment, minimum and maximum values, cached numbers, and behavior of an existing sequence. This statement affects only future sequence numbers.

How do I query sequence in SQL?

The syntax to a view the properties of a sequence in SQL Server (Transact-SQL) is: SELECT * FROM sys. sequences WHERE name = 'sequence_name'; sequence_name.


1 Answers

Use ATER SEQUENCE command:

ALTER SEQUENCE user_custom_fields_id_seq
    RESTART WITH 1000;

user_custom_fields_id_seq is not a table, it is a sequence.

like image 143
krokodilko Avatar answered Sep 27 '22 23:09

krokodilko