diff --git a/jOOQ/src/main/java/org/jooq/CreateTableCommentStep.java b/jOOQ/src/main/java/org/jooq/CreateTableCommentStep.java index cb0a25b51d..e7d72d3d90 100644 --- a/jOOQ/src/main/java/org/jooq/CreateTableCommentStep.java +++ b/jOOQ/src/main/java/org/jooq/CreateTableCommentStep.java @@ -39,6 +39,7 @@ package org.jooq; import static org.jooq.SQLDialect.MARIADB; import static org.jooq.SQLDialect.MYSQL; +import static org.jooq.SQLDialect.POSTGRES; /** * A {@link Query} that can create tables. @@ -50,13 +51,13 @@ public interface CreateTableCommentStep extends CreateTableStorageStep { /** * Add a comment to the table. */ - @Support({ MARIADB, MYSQL }) + @Support({ MARIADB, MYSQL, POSTGRES }) CreateTableStorageStep comment(String comment); /** * Add a comment to the table. */ - @Support({ MARIADB, MYSQL }) + @Support({ MARIADB, MYSQL, POSTGRES }) CreateTableStorageStep comment(Comment comment); } diff --git a/jOOQ/src/main/java/org/jooq/impl/CreateTableImpl.java b/jOOQ/src/main/java/org/jooq/impl/CreateTableImpl.java index 32a379c3ab..7dc78aab6c 100644 --- a/jOOQ/src/main/java/org/jooq/impl/CreateTableImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/CreateTableImpl.java @@ -59,6 +59,7 @@ import static org.jooq.SQLDialect.POSTGRES; // ... import static org.jooq.SQLDialect.SQLITE; // ... +import static org.jooq.impl.DSL.commentOnTable; import static org.jooq.impl.DSL.field; import static org.jooq.impl.DSL.insertInto; import static org.jooq.impl.DSL.name; @@ -125,6 +126,7 @@ final class CreateTableImpl extends AbstractQuery implements private static final EnumSet REQUIRES_WITH_DATA = EnumSet.of(HSQLDB); private static final EnumSet WRAP_SELECT_IN_PARENS = EnumSet.of(HSQLDB); private static final EnumSet SUPPORT_TEMPORARY = EnumSet.of(MARIADB, MYSQL, POSTGRES); + private static final EnumSet EMULATE_COMMENT_IN_BLOCK = EnumSet.of(POSTGRES); @@ -298,8 +300,22 @@ final class CreateTableImpl extends AbstractQuery implements } } - private final void accept0(Context ctx) { + if (comment != null && EMULATE_COMMENT_IN_BLOCK.contains(ctx.family())) { + begin(ctx); + accept1(ctx); + + ctx.sql(';').formatSeparator() + .visit(commentOnTable(table).is(comment)).sql(';'); + + end(ctx); + return; + } + + accept1(ctx); + } + + private final void accept1(Context ctx) { ctx.start(CREATE_TABLE); if (select != null) { @@ -359,7 +375,7 @@ final class CreateTableImpl extends AbstractQuery implements toSQLOnCommit(ctx); } - if (comment != null) + if (comment != null && !EMULATE_COMMENT_IN_BLOCK.contains(ctx.family())) ctx.formatSeparator() .visit(K_COMMENT).sql(' ').visit(comment);