diff --git a/crates/pgls_pretty_print/src/nodes/alter_object_schema_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_object_schema_stmt.rs index a9cfa4179..2eabe7474 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_object_schema_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_object_schema_stmt.rs @@ -112,7 +112,11 @@ pub(super) fn emit_alter_object_schema_stmt(e: &mut EventEmitter, n: &AlterObjec super::emit_node(object, e); } } - _ => super::emit_node(object, e), + _ => match &object.node { + // Qualified names (`any_name`) arrive as a list of strings + Some(NodeEnum::List(list)) => emit_dot_separated_list(e, &list.items), + _ => super::emit_node(object, e), + }, } } diff --git a/crates/pgls_pretty_print/src/nodes/rename_stmt.rs b/crates/pgls_pretty_print/src/nodes/rename_stmt.rs index 16fbfb495..b5b421ee5 100644 --- a/crates/pgls_pretty_print/src/nodes/rename_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/rename_stmt.rs @@ -1,6 +1,6 @@ use pgls_query::{ NodeEnum, - protobuf::{ObjectType, RenameStmt}, + protobuf::{DropBehavior, ObjectType, RenameStmt}, }; use crate::{ @@ -77,8 +77,17 @@ pub(super) fn emit_rename_stmt(e: &mut EventEmitter, n: &RenameStmt) { emit_keyworded_rename(e, TokenKind::CONSTRAINT_KW, &n.subname, &n.newname); } ObjectType::ObjectAttribute => { - emit_object_head(e, n); + // The composite type name is stored as a RangeVar in `relation`; it is not an + // inheritance target, so ONLY must not be emitted + if let Some(ref relation) = n.relation { + e.space(); + super::emit_range_var_name(e, relation); + } emit_attribute_rename(e, &n.subname, &n.newname); + if matches!(n.behavior(), DropBehavior::DropCascade) { + e.space(); + e.token(TokenKind::CASCADE_KW); + } } ObjectType::ObjectAggregate => { emit_aggregate_head(e, n); @@ -238,7 +247,15 @@ fn emit_relation_head(e: &mut EventEmitter, n: &RenameStmt) { fn emit_object_head(e: &mut EventEmitter, n: &RenameStmt) { if let Some(ref object) = n.object { e.space(); - emit_node(object, e); + emit_object_name(e, object); + } +} + +fn emit_object_name(e: &mut EventEmitter, object: &pgls_query::Node) { + match &object.node { + // Qualified names (`any_name`) arrive as a list of strings + Some(NodeEnum::List(list)) => emit_dot_separated_list(e, &list.items), + _ => emit_node(object, e), } } @@ -248,7 +265,7 @@ fn emit_default_head(e: &mut EventEmitter, n: &RenameStmt) { emit_range_var(e, relation); } else if let Some(ref object) = n.object { e.space(); - emit_node(object, e); + emit_object_name(e, object); } else if !n.subname.is_empty() { e.space(); emit_identifier_maybe_quoted(e, &n.subname); diff --git a/crates/pgls_pretty_print/tests/data/single/alter_object_schema_stmt_1.sql b/crates/pgls_pretty_print/tests/data/single/alter_object_schema_stmt_1.sql new file mode 100644 index 000000000..5ffc36777 --- /dev/null +++ b/crates/pgls_pretty_print/tests/data/single/alter_object_schema_stmt_1.sql @@ -0,0 +1 @@ +alter domain alter1.posint set schema alter2; diff --git a/crates/pgls_pretty_print/tests/data/single/alter_object_schema_stmt_2.sql b/crates/pgls_pretty_print/tests/data/single/alter_object_schema_stmt_2.sql new file mode 100644 index 000000000..2375a4db3 --- /dev/null +++ b/crates/pgls_pretty_print/tests/data/single/alter_object_schema_stmt_2.sql @@ -0,0 +1 @@ +alter text search configuration alter1.cfg set schema alter2; diff --git a/crates/pgls_pretty_print/tests/data/single/rename_stmt_1.sql b/crates/pgls_pretty_print/tests/data/single/rename_stmt_1.sql new file mode 100644 index 000000000..f8015be79 --- /dev/null +++ b/crates/pgls_pretty_print/tests/data/single/rename_stmt_1.sql @@ -0,0 +1 @@ +ALTER TYPE test_type2 RENAME ATTRIBUTE a TO aa CASCADE; diff --git a/crates/pgls_pretty_print/tests/data/single/rename_stmt_2.sql b/crates/pgls_pretty_print/tests/data/single/rename_stmt_2.sql new file mode 100644 index 000000000..ab559603d --- /dev/null +++ b/crates/pgls_pretty_print/tests/data/single/rename_stmt_2.sql @@ -0,0 +1 @@ +ALTER TYPE public.test_type RENAME ATTRIBUTE d TO dd; diff --git a/crates/pgls_pretty_print/tests/data/single/rename_stmt_3.sql b/crates/pgls_pretty_print/tests/data/single/rename_stmt_3.sql new file mode 100644 index 000000000..24f4b26bc --- /dev/null +++ b/crates/pgls_pretty_print/tests/data/single/rename_stmt_3.sql @@ -0,0 +1 @@ +ALTER DOMAIN s.d RENAME CONSTRAINT c TO c2; diff --git a/crates/pgls_pretty_print/tests/data/single/rename_stmt_4.sql b/crates/pgls_pretty_print/tests/data/single/rename_stmt_4.sql new file mode 100644 index 000000000..84336bd4f --- /dev/null +++ b/crates/pgls_pretty_print/tests/data/single/rename_stmt_4.sql @@ -0,0 +1 @@ +ALTER TEXT SEARCH CONFIGURATION s.cfg RENAME TO cfg2; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_object_schema_stmt_1_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_object_schema_stmt_1_100.snap new file mode 100644 index 000000000..d30b63ac9 --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_object_schema_stmt_1_100.snap @@ -0,0 +1,5 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/alter_object_schema_stmt_1.sql +--- +alter domain alter1.posint set schema alter2; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_object_schema_stmt_1_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_object_schema_stmt_1_80.snap new file mode 100644 index 000000000..d30b63ac9 --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_object_schema_stmt_1_80.snap @@ -0,0 +1,5 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/alter_object_schema_stmt_1.sql +--- +alter domain alter1.posint set schema alter2; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_object_schema_stmt_2_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_object_schema_stmt_2_100.snap new file mode 100644 index 000000000..2a34879f1 --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_object_schema_stmt_2_100.snap @@ -0,0 +1,5 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/alter_object_schema_stmt_2.sql +--- +alter text search configuration alter1.cfg set schema alter2; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_object_schema_stmt_2_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_object_schema_stmt_2_80.snap new file mode 100644 index 000000000..2a34879f1 --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_object_schema_stmt_2_80.snap @@ -0,0 +1,5 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/alter_object_schema_stmt_2.sql +--- +alter text search configuration alter1.cfg set schema alter2; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_1_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_1_100.snap new file mode 100644 index 000000000..19d45ead6 --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_1_100.snap @@ -0,0 +1,5 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/rename_stmt_1.sql +--- +alter type test_type2 rename attribute a to aa cascade; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_1_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_1_80.snap new file mode 100644 index 000000000..19d45ead6 --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_1_80.snap @@ -0,0 +1,5 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/rename_stmt_1.sql +--- +alter type test_type2 rename attribute a to aa cascade; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_2_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_2_100.snap new file mode 100644 index 000000000..0018d4d15 --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_2_100.snap @@ -0,0 +1,5 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/rename_stmt_2.sql +--- +alter type public.test_type rename attribute d to dd; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_2_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_2_80.snap new file mode 100644 index 000000000..0018d4d15 --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_2_80.snap @@ -0,0 +1,5 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/rename_stmt_2.sql +--- +alter type public.test_type rename attribute d to dd; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_3_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_3_100.snap new file mode 100644 index 000000000..fa0767233 --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_3_100.snap @@ -0,0 +1,5 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/rename_stmt_3.sql +--- +alter domain s.d rename constraint c to c2; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_3_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_3_80.snap new file mode 100644 index 000000000..fa0767233 --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_3_80.snap @@ -0,0 +1,5 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/rename_stmt_3.sql +--- +alter domain s.d rename constraint c to c2; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_4_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_4_100.snap new file mode 100644 index 000000000..729a23c2d --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_4_100.snap @@ -0,0 +1,5 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/rename_stmt_4.sql +--- +alter text search configuration s.cfg rename to cfg2; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_4_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_4_80.snap new file mode 100644 index 000000000..729a23c2d --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__rename_stmt_4_80.snap @@ -0,0 +1,5 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/rename_stmt_4.sql +--- +alter text search configuration s.cfg rename to cfg2;