Skip to content

Commit eb05ce3

Browse files
committed
Add support for 'UNLOGGED' tables
Support the PostgreSQL 9.1+ ‘UNLOGGED’ table feature
1 parent 989033d commit eb05ce3

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/main/java/net/sf/jsqlparser/statement/create/table/CreateTable.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
public class CreateTable implements Statement {
3737

3838
private Table table;
39+
private Boolean unlogged;
3940
private List<String> tableOptionsStrings;
4041
private List<ColumnDefinition> columnDefinitions;
4142
private List<Index> indexes;
@@ -57,6 +58,13 @@ public void setTable(Table table) {
5758
this.table = table;
5859
}
5960

61+
/**
62+
* Whether the table is unlogged or not (PostgreSQL 9.1+ feature)
63+
*/
64+
public Boolean isUnlogged() { return unlogged; }
65+
66+
public void setUnlogged(Boolean unlogged) { this.unlogged = unlogged; }
67+
6068
/**
6169
* A list of {@link ColumnDefinition}s of this table.
6270
*/
@@ -105,7 +113,7 @@ public void setSelect(Select select) {
105113
public String toString() {
106114
String sql = "";
107115

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

110118
if (select != null) {
111119
sql += " AS " + select.toString();

src/main/javacc/net/sf/jsqlparser/parser/JSqlParserCC.jj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
197197
| <K_RETURNING: "RETURNING">
198198
| <K_BINARY: "BINARY">
199199
| <K_REGEXP: "REGEXP">
200+
| <K_UNLOGGED: "UNLOGGED">
200201
}
201202

202203
TOKEN : /* Numeric Constants */
@@ -2034,6 +2035,7 @@ CreateTable CreateTable():
20342035
<K_CREATE>
20352036
// TODO:
20362037
// [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ]
2038+
[ <K_UNLOGGED> { createTable.setUnlogged(true); } ]
20372039
(CreateParameter())*
20382040

20392041
<K_TABLE> table=Table()

src/test/java/net/sf/jsqlparser/test/create/CreateTableTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ public void testCreateTableAsSelect2() throws JSQLParserException {
4747
}
4848

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

0 commit comments

Comments
 (0)