[#7597] CREATE TABLE with enum types generates CHECK constraint rather than enum type reference in PostgreSQL

This commit is contained in:
lukaseder 2018-06-21 16:55:48 +02:00
parent 5655f5473b
commit 838bdf47d2
2 changed files with 10 additions and 4 deletions

View File

@ -136,7 +136,7 @@ final class CreateTableImpl<R extends Record> extends AbstractQuery implements
private static final EnumSet<SQLDialect> NO_SUPPORT_IF_NOT_EXISTS = EnumSet.of(DERBY, FIREBIRD);
private static final EnumSet<SQLDialect> NO_SUPPORT_WITH_DATA = EnumSet.of(H2, MARIADB, MYSQL, SQLITE);
private static final EnumSet<SQLDialect> EMULATE_INDEXES_IN_BLOCK = EnumSet.of(POSTGRES);
private static final EnumSet<SQLDialect> EMULATE_ENUM_TYPES_AS_CHECK = EnumSet.of(CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES, SQLITE);
private static final EnumSet<SQLDialect> EMULATE_ENUM_TYPES_AS_CHECK = EnumSet.of(CUBRID, DERBY, FIREBIRD, H2, HSQLDB, SQLITE);
private static final EnumSet<SQLDialect> REQUIRES_WITH_DATA = EnumSet.of(HSQLDB);
private static final EnumSet<SQLDialect> WRAP_SELECT_IN_PARENS = EnumSet.of(HSQLDB);
private static final EnumSet<SQLDialect> SUPPORT_TEMPORARY = EnumSet.of(MARIADB, MYSQL, POSTGRES);

View File

@ -4217,7 +4217,6 @@ final class Tools {
@SuppressWarnings("unchecked")
DataType<EnumType> enumType = (DataType<EnumType>) type;
Object[] enums = enumConstants(enumType);
switch (ctx.family()) {
@ -4229,7 +4228,7 @@ final class Tools {
ctx.visit(K_ENUM).sql('(');
String separator = "";
for (Object e : enums) {
for (Object e : enumConstants(enumType)) {
ctx.sql(separator).visit(DSL.inline(((EnumType) e).getLiteral()));
separator = ", ";
}
@ -4238,8 +4237,15 @@ final class Tools {
return;
}
// [#7597] In PostgreSQL, the enum type reference should be used
case POSTGRES:
break;
default: {
type = emulateEnumType(enumType, enums);
type = emulateEnumType(enumType, enumConstants(enumType));
break;
}
}