Conversation
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.
What
Five independent output defects in the printer.
Four of them made the beta round-trip guard refuse the statement (
Normalized ASTs differ after formatting), so the user silently got no formatting at all.The fifth is a layout regression.
1.
ALTER TABLE ... ADD COLUMN IF NOT EXISTSmissing_okwas never emitted, so the statement came back withoutIF NOT EXISTSand the guard rejected it.Dropping the flag would turn an idempotent migration into one that fails on its second run, so the guard was right to refuse - the fix is to emit it.
2.
UNIQUE NULLS NOT DISTINCTon a table constraintnulls_not_distinctwas emitted forCREATE INDEXbut not for a table constraint, where the qualifier sits between the keyword and the column list:Losing it would let two NULL rows coexist where the schema forbids it.
3. A boolean expression as the argument of a boolean test
AND,ORandNOTbind more loosely than the postfixIStest, so(a OR b) IS TRUEwas printed asa or b is true, which reparses asa OR (b IS TRUE).The argument is now parenthesised when - and only when - it is a
BoolExpr.Every other argument kind binds tighter and needs nothing.
4.
DISTINCT ONparenthesesThe opening parenthesis emitted a soft line but the closing one did not, so a broken list left the
)glued to its last element:The clause now also gets its own group, so it can stay on one line while the target list breaks - the usual shape of a
DISTINCT ONquery.This changes several existing snapshots (
groupingsets,memoize,select_distinct_on,subselect,tsrf), all in that direction.5.
typeCaseon a qualified type nameCAST(t.id AS public.object_id)went through the plain identifier path, sotypeCasedid not apply to it while it applied tobigint.A new
emit_type_identifier_maybe_quotedemits aTYPE_IDENTtoken for names that can be written unquoted, and falls back to the verbatim identifier for names that need quotes -"MyType"and"MYTYPE"are two different types in PostgreSQL, so recasing them would change which type is referenced.Tests
Three new fixtures (
qualified_type_cast,distinct_on_long_list,unique_constraint_nulls_not_distinct), snapshots for two fixtures that had none (alter_table_add_column_if_not_exists,boolean_test_bool_expr), and two unit tests on the new emitter covering the quoted/unquoted split.