Skip to content

Instantly share code, notes, and snippets.

View dirablue's full-sized avatar

dirablue ( gaku ) dirablue

View GitHub Profile
@hasanisaeed
hasanisaeed / restart_squence.sql
Last active March 20, 2024 08:55
Postgres: reset sequence from max(id) in all table.
CREATE OR REPLACE FUNCTION "reset_sequence" (tablename text, columnname text, sequence_name text)
RETURNS "pg_catalog"."void" AS
$body$
DECLARE
BEGIN
EXECUTE 'SELECT setval( ''' || sequence_name || ''', ' || '(SELECT MAX(' || columnname ||
') FROM ' || tablename || ')' || '+1)';