Skip to content
Snippets Groups Projects
Commit 995bb249 authored by Christopher Lenke's avatar Christopher Lenke
Browse files

24.09.2024

parent f3e3bedf
No related branches found
No related tags found
No related merge requests found
-- DROP PROCEDURE basics.set_autoincrement(varchar, varchar);
CREATE OR REPLACE PROCEDURE basics.set_autoincrement(table_name character varying, col_name character varying)
LANGUAGE plpgsql
AS $procedure$
-- sets autoincrement on existing table starting after max value if the column
declare
max_col_value int;
BEGIN
EXECUTE format('select max(%s) from basics.%s', col_name, table_name) INTO max_col_value;
max_col_value := max_col_value +1;
execute 'drop SEQUENCE if exists basics.'||table_name ||'_'||col_name||'_seq cascade';
execute 'CREATE SEQUENCE basics.'||table_name ||'_'||col_name||'_seq START WITH '||max_col_value ;
execute 'ALTER TABLE basics.'||table_name ||' ALTER COLUMN '||col_name||'
SET DEFAULT nextval(''basics.'||table_name ||'_'||col_name||'_seq'')';
commit;
END;
$procedure$
;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment