[jOOQ/jOOQ#12888] Parser should treat AS optional in CREATE TABLE AS SELECT

This commit is contained in:
Lukas Eder 2022-01-18 10:52:25 +01:00
parent 9bb9eff764
commit db45ea6f1e

View File

@ -4274,7 +4274,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
boolean readonly = false;
boolean ctas = false;
if (parseIf('(')) {
if (!peekSelectOrWith(true) && parseIf('(')) {
columnLoop:
do {
@ -4379,8 +4379,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
if (!fields.isEmpty())
columnStep = columnStep.columns(fields);
if (ctas && parseKeyword("AS") ||
!ctas && parseKeywordIf("AS")) {
if (parseKeywordIf("AS") || peekSelectOrWith(true)) {
boolean previousMetaLookupsForceIgnore = metaLookupsForceIgnore();
CreateTableWithDataStep withDataStep = columnStep.as((Select<Record>) metaLookupsForceIgnore(false).parseQuery(true, true));
metaLookupsForceIgnore(previousMetaLookupsForceIgnore);
@ -4391,6 +4390,9 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
? withDataStep.withNoData()
: withDataStep;
}
else if (ctas) {
throw expected("AS, WITH, SELECT, or (");
}
else {
CreateTableConstraintStep constraintStep = constraints.isEmpty()
? columnStep