Jesse Long
unread,Dec 11, 2012, 7:30:09 AM12/11/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to h2-da...@googlegroups.com
Hi All,
I was excited to see the new support for SERIAL and BIGSERIAL in
1.3.170. We work predominantly in H2 and PostgreSQL, having consistent
DDL will help us a lot. Today I tried using these PostgreSQL data types
in H2 1.3.170, but found them lacking.
create table x (id bigserial not null primary key)
org.h2.jdbc.JdbcSQLException: Unknown data type: "BIGSERIAL"; SQL statement:
create table x (id bigserial not null primary key) [50004-170]
If I use SERIAL instead of BIGSERIAL, then it works, but it creates the
field as a BIGINT, not a normal INT, as is the case in PostgreSQL.
Please consider changing it ti match PostgreSQL behaviour as described
above. I think this patch may do it:
Thanks,
Jesse
Index: src/main/org/h2/value/DataType.java
===================================================================
--- src/main/org/h2/value/DataType.java (revision 4548)
+++ src/main/org/h2/value/DataType.java (working copy)
@@ -242,6 +242,12 @@
// in many cases the value is in the cache
20
);
+ add(Value.INT, Types.INTEGER, "Int",
+ createDecimal(ValueInt.PRECISION, ValueInt.PRECISION, 0,
+ ValueInt.DISPLAY_SIZE, false, true),
+ new String[]{"SERIAL"},
+ 20
+ );
add(Value.LONG, Types.BIGINT, "Long",
createDecimal(ValueLong.PRECISION, ValueLong.PRECISION, 0,
ValueLong.DISPLAY_SIZE, false, false),
@@ -251,7 +257,7 @@
add(Value.LONG, Types.BIGINT, "Long",
createDecimal(ValueLong.PRECISION, ValueLong.PRECISION, 0,
ValueLong.DISPLAY_SIZE, false, true),
- new String[]{"IDENTITY", "SERIAL"},
+ new String[]{"IDENTITY", "BIGSERIAL"},
24
);
add(Value.DECIMAL, Types.DECIMAL, "BigDecimal",
Index: src/main/org/h2/command/Parser.java
===================================================================
--- src/main/org/h2/command/Parser.java (revision 4548)
+++ src/main/org/h2/command/Parser.java (working copy)
@@ -3507,11 +3507,16 @@
private Column parseColumnForTable(String columnName, boolean
defaultNullable) {
Column column;
boolean isIdentity = false;
- if (readIf("IDENTITY") || readIf("SERIAL")) {
+ if (readIf("IDENTITY") || readIf("BIGSERIAL")) {
column = new Column(columnName, Value.LONG);
column.setOriginalSQL("IDENTITY");
parseAutoIncrement(column);
column.setPrimaryKey(true);
+ } else if (readIf("SERIAL")) {
+ column = new Column(columnName, Value.INT);
+ column.setOriginalSQL("SERIAL");
+ parseAutoIncrement(column);
+ column.setPrimaryKey(true);
} else {
column = parseColumnWithType(columnName);
}
Index: src/main/org/h2/table/Column.java
===================================================================
--- src/main/org/h2/table/Column.java (revision 4548)
+++ src/main/org/h2/table/Column.java (working copy)
@@ -355,6 +355,8 @@
}
if ("IDENTITY".equals(originalSQL)) {
originalSQL = "BIGINT";
+ } else if ("SERIAL".equals(originalSQL)) {
+ originalSQL = "INT";
}
String sequenceName;
while (true) {