diff --git a/crates/pgls_pretty_print/src/nodes/alter_table_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_table_stmt.rs index f28b039fb..25de19f51 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_table_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_table_stmt.rs @@ -103,6 +103,16 @@ fn emit_alter_table_cmd_impl(e: &mut EventEmitter, cmd: &AlterTableCmd, for_type } else { e.token(TokenKind::COLUMN_KW); } + // Dropping the flag turns an idempotent DDL into one that fails on a second run, so + // the AST round trip guard refuses the whole statement rather than let it through. + if cmd.missing_ok { + e.space(); + e.token(TokenKind::IF_KW); + e.space(); + e.token(TokenKind::NOT_KW); + e.space(); + e.token(TokenKind::EXISTS_KW); + } if let Some(ref def) = cmd.def { e.space(); e.indent_start(); diff --git a/crates/pgls_pretty_print/src/nodes/boolean_test.rs b/crates/pgls_pretty_print/src/nodes/boolean_test.rs index 32be24e37..bd0341ca3 100644 --- a/crates/pgls_pretty_print/src/nodes/boolean_test.rs +++ b/crates/pgls_pretty_print/src/nodes/boolean_test.rs @@ -10,7 +10,20 @@ pub(super) fn emit_boolean_test(e: &mut EventEmitter, n: &BooleanTest) { // Emit the argument if let Some(ref arg) = n.arg { + // AND, OR and NOT bind more loosely than the postfix IS test, so the grouping is lost + // unless it is spelled out: `(a OR b) IS TRUE` would come back as `a OR b IS TRUE`, which + // parses as `a OR (b IS TRUE)`. Every other argument kind binds tighter and needs nothing. + let needs_parens = matches!(arg.node.as_ref(), Some(pgls_query::NodeEnum::BoolExpr(_))); + + if needs_parens { + e.token(TokenKind::L_PAREN); + } + super::emit_node(arg, e); + + if needs_parens { + e.token(TokenKind::R_PAREN); + } } e.line(LineType::SoftOrSpace); diff --git a/crates/pgls_pretty_print/src/nodes/constraint.rs b/crates/pgls_pretty_print/src/nodes/constraint.rs index 841de695c..edf6b7a98 100644 --- a/crates/pgls_pretty_print/src/nodes/constraint.rs +++ b/crates/pgls_pretty_print/src/nodes/constraint.rs @@ -231,6 +231,18 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { e.token(TokenKind::UNIQUE_KW); + // For a table constraint the qualifier sits between the keyword and the column list, + // unlike CREATE INDEX where it follows the list. Dropping it would let two NULLs + // coexist where the schema forbids it. + if n.nulls_not_distinct { + e.space(); + e.token(TokenKind::NULLS_KW); + e.space(); + e.token(TokenKind::NOT_KW); + e.space(); + e.token(TokenKind::DISTINCT_KW); + } + if !n.keys.is_empty() { e.space(); e.token(TokenKind::L_PAREN); diff --git a/crates/pgls_pretty_print/src/nodes/select_stmt.rs b/crates/pgls_pretty_print/src/nodes/select_stmt.rs index 96a7ff829..f60afb733 100644 --- a/crates/pgls_pretty_print/src/nodes/select_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/select_stmt.rs @@ -348,6 +348,10 @@ fn emit_distinct_clause(e: &mut EventEmitter, clause: &[Node]) { return; } + // The clause has its own group so that it can stay on one line while the target list breaks, + // which is the usual shape of a DISTINCT ON query. + e.group_start(GroupKind::SelectStmt); + e.space(); e.token(TokenKind::ON_KW); e.space(); @@ -364,7 +368,12 @@ fn emit_distinct_clause(e: &mut EventEmitter, clause: &[Node]) { } e.indent_end(); + // Symmetric with the Soft after the opening parenthesis: without it the closing parenthesis + // stays glued to the last expression when the list breaks. + e.line(LineType::Soft); e.token(TokenKind::R_PAREN); + + e.group_end(); } /// Determines if we need parentheses around a set operation operand. diff --git a/crates/pgls_pretty_print/src/nodes/string.rs b/crates/pgls_pretty_print/src/nodes/string.rs index 5f68b5308..cccbad1ec 100644 --- a/crates/pgls_pretty_print/src/nodes/string.rs +++ b/crates/pgls_pretty_print/src/nodes/string.rs @@ -129,6 +129,22 @@ pub(super) fn emit_identifier_maybe_quoted(e: &mut EventEmitter, value: &str) { } } +/// Emits a type name part, honouring `type_case` when the name can be written unquoted. +/// +/// A name that needs quotes keeps its own spelling: `"MyType"` and `"MYTYPE"` are two different +/// types in PostgreSQL, so casing it would change which type is referenced. +pub(super) fn emit_type_identifier_maybe_quoted(e: &mut EventEmitter, value: &str) { + if value.is_empty() { + return; + } + + if needs_quoting(value) { + emit_identifier(e, value); + } else { + e.token(TokenKind::TYPE_IDENT(value.to_string())); + } +} + pub(super) fn emit_keyword(e: &mut EventEmitter, keyword: &str) { if let Some(token) = TokenKind::from_keyword(keyword) { e.token(token); @@ -254,3 +270,35 @@ fn pick_dollar_delimiter(body: &str, hint: DollarQuoteHint) -> String { counter += 1; } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::renderer::{KeywordCase, RenderConfig, Renderer}; + + fn render(value: &str, type_case: KeywordCase) -> String { + let mut emitter = EventEmitter::new(); + emit_type_identifier_maybe_quoted(&mut emitter, value); + + let mut output = String::new(); + let config = RenderConfig { + type_case, + ..Default::default() + }; + let mut renderer = Renderer::new(&mut output, config); + renderer.render(emitter.events).expect("render"); + output + } + + #[test] + fn an_unquoted_type_name_follows_the_type_case() { + assert_eq!(render("object_id", KeywordCase::Upper), "OBJECT_ID"); + assert_eq!(render("object_id", KeywordCase::Lower), "object_id"); + } + + #[test] + fn a_type_name_needing_quotes_keeps_its_own_case() { + assert_eq!(render("MyType", KeywordCase::Upper), "\"MyType\""); + assert_eq!(render("OBJECT_ID", KeywordCase::Lower), "\"OBJECT_ID\""); + } +} diff --git a/crates/pgls_pretty_print/src/nodes/type_name.rs b/crates/pgls_pretty_print/src/nodes/type_name.rs index 6553cdb76..4c93d470a 100644 --- a/crates/pgls_pretty_print/src/nodes/type_name.rs +++ b/crates/pgls_pretty_print/src/nodes/type_name.rs @@ -5,7 +5,7 @@ use crate::{ }; use pgls_query::protobuf::{self, TypeName}; -use super::string::emit_identifier_maybe_quoted; +use super::string::{emit_identifier_maybe_quoted, emit_type_identifier_maybe_quoted}; const INTERVAL_MASK_MONTH: i32 = 1 << 1; const INTERVAL_MASK_YEAR: i32 = 1 << 2; @@ -69,7 +69,7 @@ fn emit_normalized_type_name(e: &mut EventEmitter, name_parts: &[String]) { if let Some(words) = builtin_type_keywords(name_parts) { emit_keyword_sequence(e, words); } else if !name_parts.is_empty() { - emit_dot_separated_name(e, name_parts); + emit_dot_separated_type_name(e, name_parts); } else { e.token(TokenKind::IDENT("".to_string())); } @@ -93,6 +93,15 @@ fn emit_dot_separated_name(e: &mut EventEmitter, name_parts: &[String]) { } } +fn emit_dot_separated_type_name(e: &mut EventEmitter, name_parts: &[String]) { + for (index, part) in name_parts.iter().enumerate() { + if index > 0 { + e.token(TokenKind::DOT); + } + emit_type_identifier_maybe_quoted(e, part); + } +} + fn builtin_type_keywords(name_parts: &[String]) -> Option<&'static [&'static str]> { if name_parts.is_empty() { return None; diff --git a/crates/pgls_pretty_print/tests/data/single/alter_table_add_column_if_not_exists.sql b/crates/pgls_pretty_print/tests/data/single/alter_table_add_column_if_not_exists.sql new file mode 100644 index 000000000..7183e72a0 --- /dev/null +++ b/crates/pgls_pretty_print/tests/data/single/alter_table_add_column_if_not_exists.sql @@ -0,0 +1,3 @@ +ALTER TABLE s.t + ADD COLUMN IF NOT EXISTS row_id TEXT, + ADD COLUMN IF NOT EXISTS designation_source TEXT; diff --git a/crates/pgls_pretty_print/tests/data/single/boolean_test_bool_expr.sql b/crates/pgls_pretty_print/tests/data/single/boolean_test_bool_expr.sql new file mode 100644 index 000000000..24adc3067 --- /dev/null +++ b/crates/pgls_pretty_print/tests/data/single/boolean_test_bool_expr.sql @@ -0,0 +1,4 @@ +SELECT id + FROM s.units + WHERE (units.has_history OR units.has_shares OR units.has_calls) IS TRUE + AND (units.is_active AND units.is_visible) IS NOT FALSE; diff --git a/crates/pgls_pretty_print/tests/data/single/distinct_on_long_list.sql b/crates/pgls_pretty_print/tests/data/single/distinct_on_long_list.sql new file mode 100644 index 000000000..d8ec1f55b --- /dev/null +++ b/crates/pgls_pretty_print/tests/data/single/distinct_on_long_list.sql @@ -0,0 +1,3 @@ +SELECT DISTINCT ON (addresses.hash) addresses.hash AS origin_hash, addresses.entity_type, addresses.entity_fk +FROM normalization.addresses +ORDER BY addresses.hash, addresses.entity_type; diff --git a/crates/pgls_pretty_print/tests/data/single/qualified_type_cast.sql b/crates/pgls_pretty_print/tests/data/single/qualified_type_cast.sql new file mode 100644 index 000000000..1cf0078bd --- /dev/null +++ b/crates/pgls_pretty_print/tests/data/single/qualified_type_cast.sql @@ -0,0 +1,5 @@ +SELECT + CAST(t.id AS public.object_id), + CAST(t.ids AS public.object_id[]), + CAST(t.n AS bigint) +FROM s.t; diff --git a/crates/pgls_pretty_print/tests/data/single/unique_constraint_nulls_not_distinct.sql b/crates/pgls_pretty_print/tests/data/single/unique_constraint_nulls_not_distinct.sql new file mode 100644 index 000000000..da2acb364 --- /dev/null +++ b/crates/pgls_pretty_print/tests/data/single/unique_constraint_nulls_not_distinct.sql @@ -0,0 +1,5 @@ +CREATE TABLE s.expense_types ( + expense_type_legacy_id TEXT, + legacy_branch_code TEXT, + UNIQUE NULLS NOT DISTINCT (expense_type_legacy_id, legacy_branch_code) +); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_100.snap index fd4941096..b6915ee46 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_100.snap @@ -1472,9 +1472,7 @@ select not a from (values (true)) as t (a) group by rollup (not a) having not no select not a from (values (true)) as t (a) group by rollup (not a) having not not a; -select distinct on ( - a, - b) +select distinct on (a, b) a, b from @@ -1485,9 +1483,7 @@ group by grouping sets ((a, b), a) order by a, b; -select distinct on ( - a, - b) +select distinct on (a, b) a, b from @@ -1498,9 +1494,7 @@ group by grouping sets ((a, b), a) order by a, b; -select distinct on ( - a, - b + 1) +select distinct on (a, b + 1) a, b + 1 from @@ -1511,9 +1505,7 @@ group by grouping sets ((a, b + 1), a) order by a, b + 1; -select distinct on ( - a, - b + 1) +select distinct on (a, b + 1) a, b + 1 from diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_80.snap index b0c257be4..4a0ab0144 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_80.snap @@ -1933,9 +1933,7 @@ group by rollup (not a) having not not a; -select distinct on ( - a, - b) +select distinct on (a, b) a, b from @@ -1946,9 +1944,7 @@ group by grouping sets ((a, b), a) order by a, b; -select distinct on ( - a, - b) +select distinct on (a, b) a, b from @@ -1959,9 +1955,7 @@ group by grouping sets ((a, b), a) order by a, b; -select distinct on ( - a, - b + 1) +select distinct on (a, b + 1) a, b + 1 from @@ -1972,9 +1966,7 @@ group by grouping sets ((a, b + 1), a) order by a, b + 1; -select distinct on ( - a, - b + 1) +select distinct on (a, b + 1) a, b + 1 from diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__memoize_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__memoize_100.snap index def78de10..6b45c688c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__memoize_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__memoize_100.snap @@ -1,7 +1,6 @@ --- source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/memoize.sql -snapshot_kind: text --- create function explain_memoize(query text, hide_hitmiss boolean) returns setof text @@ -431,8 +430,7 @@ from tab_anti as t1 left outer join lateral ( - select distinct on ( - a) + select distinct on (a) a, b, t1.a as x diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__memoize_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__memoize_80.snap index 0f91deacb..3605e8c53 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__memoize_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__memoize_80.snap @@ -1,7 +1,6 @@ --- source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/memoize.sql -snapshot_kind: text --- create function explain_memoize(query text, hide_hitmiss boolean) returns setof text @@ -457,8 +456,7 @@ from tab_anti as t1 left outer join lateral ( - select distinct on ( - a) + select distinct on (a) a, b, t1.a as x diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_on_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_on_100.snap index 98ca0338c..f0e2791c2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_on_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_on_100.snap @@ -1,10 +1,8 @@ --- source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/select_distinct_on.sql -snapshot_kind: text --- -select distinct on ( - string4) +select distinct on (string4) string4, two, ten @@ -14,9 +12,7 @@ order by string4 using <, two using >, ten using <; -select distinct on ( - string4, - ten) +select distinct on (string4, ten) string4, two, ten @@ -26,9 +22,7 @@ order by string4 using <, two using <, ten using <; -select distinct on ( - string4, - ten) +select distinct on (string4, ten) string4, ten, two @@ -74,9 +68,7 @@ select distinct on (y, x) x, y from distinct_on_tbl order by y; select distinct on (y, x) x, y from distinct_on_tbl order by y; -select distinct on ( - y, - x) +select distinct on (y, x) x, y from @@ -88,9 +80,7 @@ order by y, x, z; -select distinct on ( - y, - x) +select distinct on (y, x) x, y from diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_on_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_on_80.snap index 263548b5b..078fae5eb 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_on_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_on_80.snap @@ -1,10 +1,8 @@ --- source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/select_distinct_on.sql -snapshot_kind: text --- -select distinct on ( - string4) +select distinct on (string4) string4, two, ten @@ -14,9 +12,7 @@ order by string4 using <, two using >, ten using <; -select distinct on ( - string4, - ten) +select distinct on (string4, ten) string4, two, ten @@ -26,9 +22,7 @@ order by string4 using <, two using <, ten using <; -select distinct on ( - string4, - ten) +select distinct on (string4, ten) string4, ten, two @@ -72,9 +66,7 @@ select distinct on (y, x) x, y from distinct_on_tbl; select distinct on (y, x) x, y from distinct_on_tbl; -select distinct on ( - y, - x) +select distinct on (y, x) x, y from @@ -83,9 +75,7 @@ from ) as s; -select distinct on ( - y, - x) +select distinct on (y, x) x, y from @@ -98,9 +88,7 @@ select distinct on (y, x) x, y from distinct_on_tbl order by y; select distinct on (y, x) x, y from distinct_on_tbl order by y; -select distinct on ( - y, - x) +select distinct on (y, x) x, y from @@ -118,9 +106,7 @@ order by y, x, z; -select distinct on ( - y, - x) +select distinct on (y, x) x, y from diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_80.snap index 4e079622e..222bb14f2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_80.snap @@ -442,8 +442,7 @@ where id2 from ( - select distinct on ( - id2) + select distinct on (id2) id1, id2 from diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsrf_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsrf_100.snap index abc773c5b..dfb0fd024 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsrf_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsrf_100.snap @@ -1,7 +1,6 @@ --- source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/tsrf.sql -snapshot_kind: text --- select generate_series(1, 3); @@ -225,8 +224,7 @@ select generate_series(1, 3) is distinct from 2; select * from int4mul(generate_series(1, 2), 10); -select distinct on ( - a) +select distinct on (a) a, b, generate_series(1, 3) as g @@ -242,8 +240,7 @@ from ) as t (a, b); -select distinct on ( - a) +select distinct on (a) a, b, generate_series(1, 3) as g @@ -261,8 +258,7 @@ from order by a, b desc; -select distinct on ( - a) +select distinct on (a) a, b, generate_series(1, 3) as g @@ -281,10 +277,7 @@ order by a, b desc, g desc; -select distinct on ( - a, - b, - g) +select distinct on (a, b, g) a, b, generate_series(1, 3) as g @@ -303,8 +296,7 @@ order by a, b desc, g desc; -select distinct on ( - g) +select distinct on (g) a, b, generate_series(1, 3) as g diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsrf_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsrf_80.snap index a40370fd3..3e8bda1a7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsrf_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsrf_80.snap @@ -1,7 +1,6 @@ --- source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/tsrf.sql -snapshot_kind: text --- select generate_series(1, 3); @@ -292,8 +291,7 @@ select generate_series(1, 3) is distinct from 2; select * from int4mul(generate_series(1, 2), 10); -select distinct on ( - a) +select distinct on (a) a, b, generate_series(1, 3) as g @@ -309,8 +307,7 @@ from ) as t (a, b); -select distinct on ( - a) +select distinct on (a) a, b, generate_series(1, 3) as g @@ -328,8 +325,7 @@ from order by a, b desc; -select distinct on ( - a) +select distinct on (a) a, b, generate_series(1, 3) as g @@ -348,10 +344,7 @@ order by a, b desc, g desc; -select distinct on ( - a, - b, - g) +select distinct on (a, b, g) a, b, generate_series(1, 3) as g @@ -370,8 +363,7 @@ order by a, b desc, g desc; -select distinct on ( - g) +select distinct on (g) a, b, generate_series(1, 3) as g diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_table_add_column_if_not_exists_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_table_add_column_if_not_exists_100.snap new file mode 100644 index 000000000..ff3de921c --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_table_add_column_if_not_exists_100.snap @@ -0,0 +1,7 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/alter_table_add_column_if_not_exists.sql +--- +alter table s.t + add column if not exists row_id text, + add column if not exists designation_source text; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_table_add_column_if_not_exists_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_table_add_column_if_not_exists_80.snap new file mode 100644 index 000000000..ff3de921c --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_table_add_column_if_not_exists_80.snap @@ -0,0 +1,7 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/alter_table_add_column_if_not_exists.sql +--- +alter table s.t + add column if not exists row_id text, + add column if not exists designation_source text; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__boolean_test_bool_expr_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__boolean_test_bool_expr_100.snap new file mode 100644 index 000000000..f4dc406d9 --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__boolean_test_bool_expr_100.snap @@ -0,0 +1,15 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/boolean_test_bool_expr.sql +--- +select + id +from + s.units +where + (units.has_history or + units.has_shares or + units.has_calls) + is true and + (units.is_active and units.is_visible) + is not false; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__boolean_test_bool_expr_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__boolean_test_bool_expr_80.snap new file mode 100644 index 000000000..f4dc406d9 --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__boolean_test_bool_expr_80.snap @@ -0,0 +1,15 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/boolean_test_bool_expr.sql +--- +select + id +from + s.units +where + (units.has_history or + units.has_shares or + units.has_calls) + is true and + (units.is_active and units.is_visible) + is not false; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__distinct_on_long_list_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__distinct_on_long_list_100.snap new file mode 100644 index 000000000..eac2bd991 --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__distinct_on_long_list_100.snap @@ -0,0 +1,12 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/distinct_on_long_list.sql +--- +select distinct on (addresses.hash) + addresses.hash as origin_hash, + addresses.entity_type, + addresses.entity_fk +from + normalization.addresses +order by addresses.hash, + addresses.entity_type; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__distinct_on_long_list_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__distinct_on_long_list_80.snap new file mode 100644 index 000000000..eac2bd991 --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__distinct_on_long_list_80.snap @@ -0,0 +1,12 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/distinct_on_long_list.sql +--- +select distinct on (addresses.hash) + addresses.hash as origin_hash, + addresses.entity_type, + addresses.entity_fk +from + normalization.addresses +order by addresses.hash, + addresses.entity_type; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__qualified_type_cast_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__qualified_type_cast_100.snap new file mode 100644 index 000000000..db7c83f1c --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__qualified_type_cast_100.snap @@ -0,0 +1,10 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/qualified_type_cast.sql +--- +select + cast(t.id as public.object_id), + cast(t.ids as public.object_id[]), + cast(t.n as bigint) +from + s.t; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__qualified_type_cast_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__qualified_type_cast_80.snap new file mode 100644 index 000000000..db7c83f1c --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__qualified_type_cast_80.snap @@ -0,0 +1,10 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/qualified_type_cast.sql +--- +select + cast(t.id as public.object_id), + cast(t.ids as public.object_id[]), + cast(t.n as bigint) +from + s.t; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__select_distinct_on_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__select_distinct_on_0_100.snap index 7f4244214..4a198c72e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__select_distinct_on_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__select_distinct_on_0_100.snap @@ -1,11 +1,8 @@ --- source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/select_distinct_on_0.sql -snapshot_kind: text --- -select distinct on ( - department_id, - team_id) +select distinct on (department_id, team_id) employee_id, team_id from diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__select_distinct_on_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__select_distinct_on_0_80.snap index 7f4244214..4a198c72e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__select_distinct_on_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__select_distinct_on_0_80.snap @@ -1,11 +1,8 @@ --- source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/select_distinct_on_0.sql -snapshot_kind: text --- -select distinct on ( - department_id, - team_id) +select distinct on (department_id, team_id) employee_id, team_id from diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__unique_constraint_nulls_not_distinct_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__unique_constraint_nulls_not_distinct_100.snap new file mode 100644 index 000000000..2646f0a62 --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__unique_constraint_nulls_not_distinct_100.snap @@ -0,0 +1,10 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/unique_constraint_nulls_not_distinct.sql +--- +create table s.expense_types ( + expense_type_legacy_id text, + legacy_branch_code text, + unique nulls not distinct (expense_type_legacy_id, + legacy_branch_code) +); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__unique_constraint_nulls_not_distinct_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__unique_constraint_nulls_not_distinct_80.snap new file mode 100644 index 000000000..2646f0a62 --- /dev/null +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__unique_constraint_nulls_not_distinct_80.snap @@ -0,0 +1,10 @@ +--- +source: crates/pgls_pretty_print/tests/tests.rs +input_file: crates/pgls_pretty_print/tests/data/single/unique_constraint_nulls_not_distinct.sql +--- +create table s.expense_types ( + expense_type_legacy_id text, + legacy_branch_code text, + unique nulls not distinct (expense_type_legacy_id, + legacy_branch_code) +);