-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: fix some type / string conversion brokenness #57354
Conversation
@otan I could use some help here: this Pr introduces a regression:
previously returns "bigint" and now returns an error "type unknown". I checked and verified the following:
Here my track runs cold. I am not entirely sure the resolution logic is even supposed to arrive to If it does, then maybe the lookup succeeds, but then the type entry becomes lost elsewhere. I suspect that the unresolved type name gets passed via |
The problem seems to be that When we had cockroach/pkg/sql/parser/sql.y Lines 9411 to 9428 in 9f9c1ce
Unfortunately, cockroach/pkg/sql/virtual_schema.go Lines 361 to 364 in 9f9c1ce
It seems like the logic here should be wholesale replaced with some mapping of known type names -> types.T, instead of relying on the parser. OR, do not escape the text, and if there is an error with the parsing logic error out silently. |
Actually, maybe this is a good thing. This does not work on PG either:
|
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.
Reviewed 11 of 13 files at r1.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @jordanlewis, @knz, and @otan)
pkg/sql/sem/tree/eval.go, line 3032 at r1 (raw file):
// GetTypeFromValidSQLSyntax parses a column type when the input // string uses the parseable SQL representation of a type name, e.g. // "INT(13)" or "pg_catalog.int".
nit: i don't think pg_catalog.int
would work here as the schema separator .
would be folded in, i.e. we'd be doing SELECT 1::"pg_catalog.int"
which is invalid.
(accept assumes we don't want to allow int as a type, but the user must use the full name, i.e. int4, int8... may be worth noting explicitly in the release note if that is the case) |
Aaayyy yes indeed! That is awesome. Thanks. |
@otan I changed the comment you suggested, also added some tests. PTAL. |
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.
Reviewed 1 of 13 files at r1, 7 of 7 files at r2.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @jordanlewis and @knz)
pkg/sql/logictest/testdata/logic_test/drop_type, line 349 at r2 (raw file):
CREATE TYPE d."b+c" AS ENUM('hello') query
remove for tests to pass
pkg/sql/logictest/testdata/logic_test/drop_type, line 355 at r2 (raw file):
statement ok DROP DATABASE d;
nit: remove trailing ;
pkg/sql/sem/tree/eval.go, line 3032 at r1 (raw file):
Previously, otan (Oliver Tan) wrote…
nit: i don't think
pg_catalog.int
would work here as the schema separator.
would be folded in, i.e. we'd be doingSELECT 1::"pg_catalog.int"
which is invalid.
remove pg_catalog.
here?
thanks for jumping onto this @knz ! |
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 @jordanlewis and @otan)
pkg/sql/logictest/testdata/logic_test/drop_type, line 349 at r2 (raw file):
Previously, otan (Oliver Tan) wrote…
remove for tests to pass
Done.
pkg/sql/logictest/testdata/logic_test/drop_type, line 355 at r2 (raw file):
Previously, otan (Oliver Tan) wrote…
nit: remove trailing ;
Done
pkg/sql/sem/tree/eval.go, line 3032 at r1 (raw file):
Previously, otan (Oliver Tan) wrote…
remove
pg_catalog.
here?
Nah actually it's meant to work. Added more examples.
TFYR! bors r=otan |
Build failed: |
This ensures that e.g. `drop type "a+b"` works if there is a type indeed named `a+b`. Release note (bug fix): DROP TYPE and certain other statements that work over SQL scalar types now properly support type names containing special characters.
bors r=otan |
Build succeeded: |
Shall we backport this to 20.2? |
that works for me |
Fixes #57347
Fixes #57187
This ensures that e.g.
drop type "a+b"
works if there is a typeindeed named
a+b
.Release note (bug fix): DROP TYPE and certain other statements that
work over SQL scalar types now properly support type names containing
special characters.