Skip to content

Commit 4f06065

Browse files
committed
PostgreSQL: Fix REPLICA IDENTITY to use NOTHING
PR apache#1844 added `REPLICA IDENTITY` support, but mistakenly used `NONE` instead of `NOTHING`.
1 parent 6550ec8 commit 4f06065

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

src/ast/ddl.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ impl fmt::Display for IndexColumn {
9999
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
100100
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
101101
pub enum ReplicaIdentity {
102-
/// No replica identity (`REPLICA IDENTITY NONE`).
103-
None,
102+
/// No replica identity (`REPLICA IDENTITY NOTHING`).
103+
Nothing,
104104
/// Full replica identity (`REPLICA IDENTITY FULL`).
105105
Full,
106106
/// Default replica identity (`REPLICA IDENTITY DEFAULT`).
@@ -112,7 +112,7 @@ pub enum ReplicaIdentity {
112112
impl fmt::Display for ReplicaIdentity {
113113
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
114114
match self {
115-
ReplicaIdentity::None => f.write_str("NONE"),
115+
ReplicaIdentity::Nothing => f.write_str("NOTHING"),
116116
ReplicaIdentity::Full => f.write_str("FULL"),
117117
ReplicaIdentity::Default => f.write_str("DEFAULT"),
118118
ReplicaIdentity::Index(idx) => write!(f, "USING INDEX {idx}"),
@@ -1893,7 +1893,7 @@ pub enum ColumnOption {
18931893
/// [ MATCH { FULL | PARTIAL | SIMPLE } ]
18941894
/// { [ON DELETE <referential_action>] [ON UPDATE <referential_action>] |
18951895
/// [ON UPDATE <referential_action>] [ON DELETE <referential_action>]
1896-
/// }
1896+
/// }
18971897
/// [<constraint_characteristics>]
18981898
/// `).
18991899
ForeignKey(ForeignKeyConstraint),
@@ -4345,7 +4345,7 @@ impl Spanned for CreateExtension {
43454345
}
43464346
}
43474347

4348-
/// DROP EXTENSION statement
4348+
/// DROP EXTENSION statement
43494349
/// Note: this is a PostgreSQL-specific statement
43504350
///
43514351
/// # References

src/parser/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10119,8 +10119,8 @@ impl<'a> Parser<'a> {
1011910119
let value = self.parse_number_value()?;
1012010120
AlterTableOperation::AutoIncrement { equals, value }
1012110121
} else if self.parse_keywords(&[Keyword::REPLICA, Keyword::IDENTITY]) {
10122-
let identity = if self.parse_keyword(Keyword::NONE) {
10123-
ReplicaIdentity::None
10122+
let identity = if self.parse_keyword(Keyword::NOTHING) {
10123+
ReplicaIdentity::Nothing
1012410124
} else if self.parse_keyword(Keyword::FULL) {
1012510125
ReplicaIdentity::Full
1012610126
} else if self.parse_keyword(Keyword::DEFAULT) {
@@ -10129,7 +10129,7 @@ impl<'a> Parser<'a> {
1012910129
ReplicaIdentity::Index(self.parse_identifier()?)
1013010130
} else {
1013110131
return self.expected(
10132-
"NONE, FULL, DEFAULT, or USING INDEX index_name after REPLICA IDENTITY",
10132+
"NOTHING, FULL, DEFAULT, or USING INDEX index_name after REPLICA IDENTITY",
1013310133
self.peek_token(),
1013410134
);
1013510135
};

tests/sqlparser_postgres.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6568,6 +6568,30 @@ fn parse_alter_table_replica_identity() {
65686568
}
65696569
_ => unreachable!(),
65706570
}
6571+
6572+
match pg_and_generic().verified_stmt("ALTER TABLE foo REPLICA IDENTITY NOTHING") {
6573+
Statement::AlterTable(AlterTable { operations, .. }) => {
6574+
assert_eq!(
6575+
operations,
6576+
vec![AlterTableOperation::ReplicaIdentity {
6577+
identity: ReplicaIdentity::Nothing
6578+
}]
6579+
);
6580+
}
6581+
_ => unreachable!(),
6582+
}
6583+
6584+
match pg_and_generic().verified_stmt("ALTER TABLE foo REPLICA IDENTITY DEFAULT") {
6585+
Statement::AlterTable(AlterTable { operations, .. }) => {
6586+
assert_eq!(
6587+
operations,
6588+
vec![AlterTableOperation::ReplicaIdentity {
6589+
identity: ReplicaIdentity::Default
6590+
}]
6591+
);
6592+
}
6593+
_ => unreachable!(),
6594+
}
65716595
}
65726596

65736597
#[test]

0 commit comments

Comments
 (0)