Skip to content

Commit 6980f43

Browse files
committed
fix(parser): restore PostgreSQL REPLICA IDENTITY NOTHING
Signed-off-by: minleejae <mmj9808@gmail.com>
1 parent 2b3bebe commit 6980f43

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18880,7 +18880,7 @@ RelationAlterAction PostgreSqlRelationAction():
1888018880
(
1888118881
<K_USING> <K_INDEX> name=RelObjectName()
1888218882
{ action.setReplicaIdentity(RelationAlterAction.ReplicaIdentity.USING_INDEX); action.setValue(name); }
18883-
| ( token=<K_DEFAULT> | token=<K_FULL> | token=<S_IDENTIFIER> )
18883+
| ( token=<K_DEFAULT> | token=<K_FULL> | token=<K_NOTHING> | token=<S_IDENTIFIER> )
1888418884
{ action.setReplicaIdentity(accessEnum(RelationAlterAction.ReplicaIdentity.class, token.image)); }
1888518885
)
1888618886
|

‎src/test/java/net/sf/jsqlparser/statement/alter/PostgreSqlRelationAlterTest.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package net.sf.jsqlparser.statement.alter;
1111

12+
import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed;
1213
import static org.junit.jupiter.api.Assertions.*;
1314
import java.util.ArrayList;
1415
import java.util.List;
@@ -80,6 +81,7 @@ class PostgreSqlRelationAlterTest {
8081
"ALTER TABLE t RESET(toast.autovacuum_enabled,fillfactor)",
8182
"ALTER TABLE t INHERIT p",
8283
"ALTER TABLE t NO INHERIT p",
84+
"ALTER TABLE t REPLICA IDENTITY NOTHING",
8385
"ALTER TABLE t REPLICA IDENTITY USING INDEX ix",
8486
"ALTER TABLE t SET ACCESS METHOD heap"})
8587
void auditedActionsAreStructuredAndRoundTrip(String sql) throws JSQLParserException {
@@ -96,6 +98,23 @@ void auditedActionsAreStructuredAndRoundTrip(String sql) throws JSQLParserExcept
9698
p -> p.withDialect(Dialect.POSTGRESQL)).size());
9799
}
98100

101+
@ParameterizedTest
102+
@ValueSource(strings = {"DEFAULT", "FULL", "NOTHING"})
103+
void replicaIdentityModesAreStructuredAndEditable(String mode) throws JSQLParserException {
104+
Alter statement = (Alter) assertSqlCanBeParsedAndDeparsed(
105+
"ALTER TABLE t REPLICA IDENTITY " + mode, false,
106+
parser -> parser.withDialect(Dialect.POSTGRESQL));
107+
RelationAlterAction action = assertInstanceOf(RelationAlterAction.class,
108+
statement.getAlterExpressions().get(0));
109+
assertEquals(RelationAlterAction.Kind.REPLICA_IDENTITY, action.getKind());
110+
assertEquals(RelationAlterAction.ReplicaIdentity.valueOf(mode), action.getReplicaIdentity());
111+
assertRoundTrip(statement);
112+
113+
action.setReplicaIdentity(RelationAlterAction.ReplicaIdentity.NOTHING);
114+
assertEquals("ALTER TABLE t REPLICA IDENTITY NOTHING", statement.toString());
115+
assertRoundTrip(statement);
116+
}
117+
99118
@Test
100119
void indexNameAndActionParametersCanBeReplaced() throws JSQLParserException {
101120
AlterRelation index =

0 commit comments

Comments
 (0)