Skip to content

Commit 644f261

Browse files
authored
Added support for sequences with minvalue defined (#1429)
When a sequence is defined with a minimum value, and the sequence to migrate is empty, the setval fails due to 1 being the default (which may be lower than the defined minimum value) Signed-off-by: Christoph Engelbert (noctarius) <me@noctarius.com>
1 parent 8ff0c57 commit 644f261

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/pgsql/pgsql-create-schema.lisp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ BEGIN
408408
|| trim(trailing ')'
409409
from replace(pg_get_expr(d.adbin, d.adrelid),
410410
'nextval', 'setval'))
411-
|| ', (select greatest(max(' || quote_ident(a.attname) || '), 1) from only '
411+
|| ', (select greatest(max(' || quote_ident(a.attname) || '), (select seqmin from pg_sequence where seqrelid = ('''
412+
|| pg_get_serial_sequence(quote_ident(nspname) || '.' || quote_ident(relname), quote_ident(a.attname)) || ''')::regclass limit 1), 1) from only '
412413
|| quote_ident(nspname) || '.' || quote_ident(relname) || '));' as sql
413414
FROM pg_class c
414415
JOIN pg_namespace n on n.oid = c.relnamespace

0 commit comments

Comments
 (0)