Repository navigation
fix(pretty_print): indent the condition of a check constraint - #871
Merged
Merged
Conversation
A CHECK condition now uses the parenthesized-condition layout of a policy's using (...): it stays on one line when it fits, and otherwise breaks after the opening parenthesis, indents the condition and puts the closing parenthesis back at the constraint's indent. A constraint is not a clause, so its condition follows the line width in expanded layout too. Once it breaks, expanded layout puts each operand of its and/or chain on its own line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CHECK conditions printed
check (+ condition +)with no indent and no break after(, so a broken condition continued at theconstraintline's indent. This happened with the default fit layout once a condition was too long. Withlayout: expandedit happened for everyand/or, even in a shortcheck (a or b).CHECK conditions now use the parenthesized-condition layout that policies got in #857. A condition stays on one line when it fits. Otherwise the line breaks after
(, the condition is indented one level, and)goes back to the constraint's indent, followed byno inherit/not valid. This applies everywhere a CHECK is printed: table and column constraints in CREATE TABLE, ALTER TABLE ... ADD, CREATE DOMAIN and ALTER DOMAIN ... ADD CONSTRAINT.Expanded layout
A constraint is not a clause, so its condition follows the line width even with
layout: expanded, like select-list-only subqueries in #857. Once a constraint breaks, expanded layout puts each operand of the top-leveland/orchain on its own line. The chain is emitted in the parentheses' group rather than a group of its own, so both break together. Nested groups such as(a and b)still stay on one line when they fit.Before (
layout: expanded,logicalOperatorPlacement: leading,lineWidth: 120):After:
Changed snapshots
New
check_constraint_bodyfixtures cover the issue's statements plus a long table CHECK, a column-level CHECK, a CHECK withno inherit, ALTER TABLE ...not valid, and CREATE/ALTER DOMAIN, under the default, expanded, and expanded + compact + leading (width 120) settings. All existing snapshot changes are CHECK conditions that previously didn't fit:merge,create_stmt_cast_check_0): operands now sit indented insidecheck (…)instead of at the constraint's indent.betweenandnot (...)conditions (alter_table,constraints): break after(, and) not validfollows the closing parenthesis.email_address_type): the comparison is indented inside the parentheses.sqljson_queryfuncs): the function call is indented inside the parentheses. At width 100 some now fit on one line. The JSON functions' own argument layout and their double space beforereturningare unchanged; both already show up elsewhere on main.Fixes #866