> sequences
H2 doesn't support all the features that PostgreSQL does for
sequences. H2 doesn't support MAXVALUE and NO MINVALUE. There is
already a feature request for this, I have move this up in the list
(http://groups.google.com/group/h2-database/web/roadmap).
> The CREATE SEQUENCE and ALTER SEQUENCE commands take a 'long' datatype
> as a parameter, which excludes using the usual functions or a subquery
> to get the current maximum primary key from the table.
Yes, currently this is done using:
ALTER SEQUENCE seq_sample_id RESTART WITH 23
See: http://www.h2database.com/html/grammar.html#sql11
> SELECT pg_catalog.setval('seq_sample_id', 22, true);
What about:
public class Test {
public static Long setSequenceValue(Connection conn, String
sequenceName, Long value, Boolean isCalled) throws SQLException {
boolean isCalledValue = isCalled == null ? true : isCalled.booleanValue();
conn.createStatement().execute("ALTER SEQUENCE " + sequenceName + "
RESTART WITH " + value);
return value;
}
}
DROP SEQUENCE TEST;
CREATE SEQUENCE TEST;
CREATE ALIAS SETVAL FOR "Test.setSequenceValue";
CALL SETVAL('TEST', 22, FALSE);
CALL SETVAL('TEST', (SELECT 22+1), FALSE);
Regards,
Thomas