Skip to content

Commit 380b7da

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 802c7d3 commit 380b7da

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}"),
@@ -1911,7 +1911,7 @@ pub enum ColumnOption {
19111911
/// [ MATCH { FULL | PARTIAL | SIMPLE } ]
19121912
/// { [ON DELETE <referential_action>] [ON UPDATE <referential_action>] |
19131913
/// [ON UPDATE <referential_action>] [ON DELETE <referential_action>]
1914-
/// }
1914+
/// }
19151915
/// [<constraint_characteristics>]
19161916
/// `).
19171917
ForeignKey(ForeignKeyConstraint),
@@ -4363,7 +4363,7 @@ impl Spanned for CreateExtension {
43634363
}
43644364
}
43654365

4366-
/// DROP EXTENSION statement
4366+
/// DROP EXTENSION statement
43674367
/// Note: this is a PostgreSQL-specific statement
43684368
///
43694369
/// # References

src/parser/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10140,8 +10140,8 @@ impl<'a> Parser<'a> {
1014010140
let value = self.parse_number_value()?;
1014110141
AlterTableOperation::AutoIncrement { equals, value }
1014210142
} else if self.parse_keywords(&[Keyword::REPLICA, Keyword::IDENTITY]) {
10143-
let identity = if self.parse_keyword(Keyword::NONE) {
10144-
ReplicaIdentity::None
10143+
let identity = if self.parse_keyword(Keyword::NOTHING) {
10144+
ReplicaIdentity::Nothing
1014510145
} else if self.parse_keyword(Keyword::FULL) {
1014610146
ReplicaIdentity::Full
1014710147
} else if self.parse_keyword(Keyword::DEFAULT) {
@@ -10150,7 +10150,7 @@ impl<'a> Parser<'a> {
1015010150
ReplicaIdentity::Index(self.parse_identifier()?)
1015110151
} else {
1015210152
return self.expected(
10153-
"NONE, FULL, DEFAULT, or USING INDEX index_name after REPLICA IDENTITY",
10153+
"NOTHING, FULL, DEFAULT, or USING INDEX index_name after REPLICA IDENTITY",
1015410154
self.peek_token(),
1015510155
);
1015610156
};

tests/sqlparser_postgres.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6637,6 +6637,30 @@ fn parse_alter_table_replica_identity() {
66376637
}
66386638
_ => unreachable!(),
66396639
}
6640+
6641+
match pg_and_generic().verified_stmt("ALTER TABLE foo REPLICA IDENTITY NOTHING") {
6642+
Statement::AlterTable(AlterTable { operations, .. }) => {
6643+
assert_eq!(
6644+
operations,
6645+
vec![AlterTableOperation::ReplicaIdentity {
6646+
identity: ReplicaIdentity::Nothing
6647+
}]
6648+
);
6649+
}
6650+
_ => unreachable!(),
6651+
}
6652+
6653+
match pg_and_generic().verified_stmt("ALTER TABLE foo REPLICA IDENTITY DEFAULT") {
6654+
Statement::AlterTable(AlterTable { operations, .. }) => {
6655+
assert_eq!(
6656+
operations,
6657+
vec![AlterTableOperation::ReplicaIdentity {
6658+
identity: ReplicaIdentity::Default
6659+
}]
6660+
);
6661+
}
6662+
_ => unreachable!(),
6663+
}
66406664
}
66416665

66426666
#[test]

0 commit comments

Comments
 (0)