// Optional IF NOT EXISTS, irrelevant for our purposes
parser.expectOptional("IF", "NOT", "EXISTS");
final String tableName = parser.parseIdentifier();
final PgTable table = new PgTable(ParserUtils.getObjectName(tableName));
final String schemaName =
ParserUtils.getSchemaName(tableName, database);
final PgSchema schema = database.getSchema(schemaName);
if (schema == null) {
throw new RuntimeException(MessageFormat.format(
Resources.getString("CannotFindSchema"), schemaName,
statement));
}
schema.addTable(table);
parser.expect("(");
while (!parser.expectOptional(")")) {
if (parser.expectOptional("CONSTRAINT")) {
parseConstraint(parser, table);
} else {
parseColumn(parser, table);
}
if (parser.expectOptional(")")) {
break;
} else {
parser.expect(",");
}
}
while (!parser.expectOptional(";")) {
if (parser.expectOptional("INHERITS")) {
parseInherits(parser, table);
} else if (parser.expectOptional("WITHOUT")) {
table.setWith("OIDS=false");
} else if (parser.expectOptional("WITH")) {
if (parser.expectOptional("OIDS")
|| parser.expectOptional("OIDS=true")) {
table.setWith("OIDS=true");
} else if (parser.expectOptional("OIDS=false")) {
table.setWith("OIDS=false");
} else {
table.setWith(parser.getExpression());
}
} else if (parser.expectOptional("TABLESPACE")) {
table.setTablespace(parser.parseString());
} else {
parser.throwUnsupportedCommand();
}
}
}