Search
 
SCRIPT & CODE EXAMPLE
 

SQL

setval pgsql

-- Login to psql and run the following

-- What is the result?
SELECT MAX(id) FROM your_table;

-- Then run...
-- This should be higher than the last result.
SELECT nextval('your_table_id_seq');

-- If it's not higher... run this set the sequence last to your highest id. 
-- (wise to run a quick pg_dump first...)

BEGIN;
-- protect against concurrent inserts while you update the counter
LOCK TABLE your_table IN EXCLUSIVE MODE;
-- Update the sequence
SELECT setval('your_table_id_seq', COALESCE((SELECT MAX(id)+1 FROM your_table), 1), false);
COMMIT;
Comment

PREVIOUS NEXT
Code Example
Sql :: oracle show trigger code 
Sql :: sql query to copy data from one column to another 
Sql :: cursor in sql server 
Sql :: how to select department from table 
Sql :: copy sql table 
Sql :: mysql events not work 
Sql :: oracle set date format 
Sql :: oracle apex prevent initial load 
Sql :: sql delete stored procedure 
Sql :: capitalize 1st letter in sql server 
Sql :: oracle plan hash value 
Sql :: select * from table where name like 
Sql :: sql server for loop 
Sql :: mysql case when null 
Sql :: sql random decimal 
Sql :: t-sql select min from two values 
Sql :: how to get weekday from old date in sql 
Sql :: firebase bigquery cloud message 
Sql :: sql query length of string the longest 
Sql :: inner join in update query mysql 
Sql :: how to drop a trigger in postgresql 
Sql :: create column sql server 
Sql :: create table mysql 
Sql :: mysql concatenate columns 
Sql :: oracle create as select 
Sql :: sql auto date 
Sql :: mysql load data infile csv 
Sql :: oracle index partition 
Sql :: mysql alter table modify column 
Sql :: show column from sql server 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =