Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
public class CreateTable implements Statement {

private Table table;
private Boolean unlogged;
private List<String> tableOptionsStrings;
private List<ColumnDefinition> columnDefinitions;
private List<Index> indexes;
Expand All @@ -57,6 +58,13 @@ public void setTable(Table table) {
this.table = table;
}

/**
* Whether the table is unlogged or not (PostgreSQL 9.1+ feature)
*/
public Boolean isUnlogged() { return unlogged; }

public void setUnlogged(Boolean unlogged) { this.unlogged = unlogged; }

/**
* A list of {@link ColumnDefinition}s of this table.
*/
Expand Down Expand Up @@ -105,7 +113,7 @@ public void setSelect(Select select) {
public String toString() {
String sql = "";

sql = "CREATE TABLE " + table;
sql = "CREATE " + (unlogged != null && unlogged ? "UNLOGGED " : "") + "TABLE " + table;

if (select != null) {
sql += " AS " + select.toString();
Expand Down
2 changes: 2 additions & 0 deletions src/main/javacc/net/sf/jsqlparser/parser/JSqlParserCC.jj
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
| <K_RETURNING: "RETURNING">
| <K_BINARY: "BINARY">
| <K_REGEXP: "REGEXP">
| <K_UNLOGGED: "UNLOGGED">
}

TOKEN : /* Numeric Constants */
Expand Down Expand Up @@ -2034,6 +2035,7 @@ CreateTable CreateTable():
<K_CREATE>
// TODO:
// [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ]
[ <K_UNLOGGED> { createTable.setUnlogged(true); } ]
(CreateParameter())*

<K_TABLE> table=Table()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ public void testCreateTableAsSelect2() throws JSQLParserException {
}

public void testCreateTable() throws JSQLParserException {
String statement = "CREATE TABLE mytab (mycol a (10, 20) c nm g, mycol2 mypar1 mypar2 (23,323,3) asdf ('23','123') dasd, "
String statement = "CREATE UNLOGGED TABLE mytab (mycol a (10, 20) c nm g, mycol2 mypar1 mypar2 (23,323,3) asdf ('23','123') dasd, "
+ "PRIMARY KEY (mycol2, mycol)) type = myisam";
CreateTable createTable = (CreateTable) parserManager.parse(new StringReader(statement));
assertEquals(2, createTable.getColumnDefinitions().size());
assertTrue(createTable.isUnlogged());
assertEquals("mycol", ((ColumnDefinition) createTable.getColumnDefinitions().get(0)).getColumnName());
assertEquals("mycol2", ((ColumnDefinition) createTable.getColumnDefinitions().get(1)).getColumnName());
assertEquals("PRIMARY KEY", ((Index) createTable.getIndexes().get(0)).getType());
Expand Down