-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Conversation
31eba46
to
c2681bd
Compare
c2681bd
to
8a8dc81
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status:
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status:
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 thetypedExpr
? 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!
8a8dc81
to
c40e38c
Compare
There was a problem hiding this 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! modulo a couple of nits re: the comments for future us!
Reviewable status:
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status:
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.
c40e38c
to
781b3ac
Compare
bors r=arulajmani |
Build succeeded: |
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.