Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: format arrays in pg_catalog to match Postgres #56980

Merged
merged 1 commit into from
Dec 7, 2020

Conversation

rafiss
Copy link
Collaborator

@rafiss rafiss commented Nov 20, 2020

Postgres uses the curly brace syntax to display array constants that are
in pg_catalog, like those in default expressions.

CockroachDB stores arrays in descriptors as tree.Array exprs, so in
order to use the curly brace syntax, now we check if the array has any
variables or functions, and if not, we turn the Array expr into a
DArray. The formatting logic for DArrays also is updated to use single
quotes as appropriate, when formatting for pg_catalog.

fixes #55320

Release note (sql change): Arrays in pg_catalog tables now are displyed
in a format that matches PostgreSQL.

@rafiss rafiss requested review from jordanlewis and a team November 20, 2020 23:58
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @arulajmani, @jordanlewis, and @rafiss)


pkg/sql/catalog/schemaexpr/expr.go, line 202 at r1 (raw file):

		sanitizedExpr, err := SanitizeVarFreeExpr(ctx, expr, typedExpr.ResolvedType(), "FORMAT", semaCtx,
			tree.VolatilityImmutable)
		if err == nil {

This err == nil could use some commentary. Better yet, are we expecting a particular type of error here in case we want to fall back to the typedExpr? If so, can we check for that and be more explicit?

Copy link
Collaborator Author

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @arulajmani and @jordanlewis)


pkg/sql/catalog/schemaexpr/expr.go, line 202 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

This err == nil could use some commentary. Better yet, are we expecting a particular type of error here in case we want to fall back to the typedExpr? If so, can we check for that and be more explicit?

i don't think we can check for a specific error. the error could be

pgerror.Newf(pgcode.Syntax,
			"variable sub-expressions are not allowed in %s", context)

or anything from the typechecker rejecting the volatility of the expression

agree on commenting!

Copy link
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the changes! :lgtm: modulo a couple of nits re: the comments for future us!

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @arulajmani, @jordanlewis, and @rafiss)


pkg/sql/catalog/schemaexpr/expr.go, line 202 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

i don't think we can check for a specific error. the error could be

pgerror.Newf(pgcode.Syntax,
			"variable sub-expressions are not allowed in %s", context)

or anything from the typechecker rejecting the volatility of the expression

agree on commenting!

nit: the comment about an empty EvalContext might be misplaced -- shouldn't it go above the d, err := sanitizedExpr.Eval(&tree.EvalContext()) line?

nit: Could you also add a nod to the fact that this is best effort and we can fall back on returning an expression if we can't convert it to a constant?

Copy link
Collaborator Author

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @arulajmani and @jordanlewis)


pkg/sql/catalog/schemaexpr/expr.go, line 202 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

nit: the comment about an empty EvalContext might be misplaced -- shouldn't it go above the d, err := sanitizedExpr.Eval(&tree.EvalContext()) line?

nit: Could you also add a nod to the fact that this is best effort and we can fall back on returning an expression if we can't convert it to a constant?

thanks -- i shouldn't have moved that comment. also adding the other one

Postgres uses the curly brace syntax to display array constants that are
in pg_catalog, like those in default expressions.

CockroachDB stores arrays in descriptors as tree.Array exprs, so in
order to use the curly brace syntax, now we check if the array has any
variables or functions, and if not, we turn the Array expr into a
DArray. The formatting logic for DArrays also is updated to use single
quotes as appropriate, when formatting for pg_catalog.

Release note (sql change): Arrays in pg_catalog tables now are diaplyed
in a format that matches PostgreSQL.
@rafiss
Copy link
Collaborator Author

rafiss commented Dec 7, 2020

bors r=arulajmani

@craig
Copy link
Contributor

craig bot commented Dec 7, 2020

Build succeeded:

@craig craig bot merged commit 88d74a0 into cockroachdb:master Dec 7, 2020
@rafiss rafiss deleted the default-arrays branch January 4, 2021 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: default values for arrays formatted incorrectly in pg_attrdef.adbin
3 participants