Skip to content

Instantly share code, notes, and snippets.

@unarist
Created December 18, 2013 16:06
Show Gist options
  • Save unarist/8024930 to your computer and use it in GitHub Desktop.
Save unarist/8024930 to your computer and use it in GitHub Desktop.
PostgreSQLでシーケンスを今の最大値にリセットする ref: http://qiita.com/unarist@github/items/1ef370933d5745d9c336
select
'select setval(''' || sequence || ''', (select max(' || column_name || ') from ' || table_name || '));' as setval
from
(
select
table_name
, column_name
, substr(column_default, 10, length(column_default) - 21) as sequence
from
information_schema.columns
where
table_schema = 'public'
and column_default like 'nextval(%'
) a;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment