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

plpgsql: support syntax to use column/table type for variable #114676

Open
DrewKimball opened this issue Nov 17, 2023 · 1 comment
Open

plpgsql: support syntax to use column/table type for variable #114676

DrewKimball opened this issue Nov 17, 2023 · 1 comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. docs-known-limitation docs-todo O-qa P-3 Issues/test failures with no fix SLA T-sql-queries SQL Queries Team

Comments

@DrewKimball
Copy link
Collaborator

DrewKimball commented Nov 17, 2023

Postgres allows PLpgSQL variable declarations to inherit the type of a table row or column using special syntax (docs):

name table_name%ROWTYPE; -- Row type
name var/col%TYPE -- Type of column or variable

This issue tracks adding support for this syntax.

CRDB does not yet support this syntax, but instead of returning an "unsupported" error, we currently return an internal error during parsing:

root@localhost:26257/system/defaultdb> CREATE TABLE xy (x INT, y INT);
CREATE TABLE

Time: 41ms total (execution 40ms / network 0ms)

root@localhost:26257/system/defaultdb> CREATE PROCEDURE foo() LANGUAGE PLpgSQL AS $$ DECLARE a xy%ROWTYPE; BEGIN END $$;
ERROR: internal error: at or near "rowtype": syntax error: expected a tree.CastExpr, but found *tree.BinaryExpr
SQLSTATE: XX000
DETAIL: source SQL:
DECLARE a xy%ROWTYPE; BEGIN END
             ^stack trace:
github.com/cockroachdb/cockroach/pkg/sql/parser/parse.go:414: GetTypeFromCastOrCollate()
github.com/cockroachdb/cockroach/pkg/sql/parser/parse.go:398: GetTypeFromValidSQLSyntax()
github.com/cockroachdb/cockroach/pkg/sql/plpgsql/parser/lexer.go:477: GetTypeFromValidSQLSyntax()
plpgsql-gen.y:554: Parse()
github.com/cockroachdb/cockroach/pkg/sql/plpgsql/parser/parse.go:101: parse()
github.com/cockroachdb/cockroach/pkg/sql/plpgsql/parser/parse.go:85: parseWithDepth()
github.com/cockroachdb/cockroach/pkg/sql/plpgsql/parser/parse.go:135: Parse()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/create_function.go:245: buildCreateFunction()

Jira issue: CRDB-33620

@DrewKimball DrewKimball added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-qa labels Nov 17, 2023
@michae2 michae2 added the P-3 Issues/test failures with no fix SLA label Nov 21, 2023
@yuzefovich yuzefovich added the T-sql-queries SQL Queries Team label Nov 21, 2023
@yuzefovich
Copy link
Member

We saw this get triggered at least once in the wild #121876.

DrewKimball added a commit to DrewKimball/cockroach that referenced this issue Apr 18, 2024
Previously, when parsing the type of a declared PL/pgSQL variable, the
parser could return an internal error when attempting to parse an
expression like `xy@ROWTYPE`. This syntax, isn't currently supported in
CRDB, but shouldn't result in an internal error, either. Now, the parser
has inlined some logic from `GetTypeFromCastOrCollate` and will now return
an expected syntax error instead.

Fixes cockroachdb#114676

Release note (bug fix): Fixed a bug that could result in an internal error
when attempting to create a PL/pgSQL routine using the (currently unsupported)
`%ROWTYPE` syntax for a variable declaration.
@DrewKimball DrewKimball self-assigned this Apr 18, 2024
DrewKimball added a commit to DrewKimball/cockroach that referenced this issue Apr 23, 2024
Previously, when parsing the type of a declared PL/pgSQL variable, the
parser could return an internal error when attempting to parse an
expression like `xy@ROWTYPE`. This syntax, isn't currently supported in
CRDB, but shouldn't result in an internal error, either. Now, the parser
has inlined some logic from `GetTypeFromCastOrCollate` and will now return
an expected syntax error instead.

Informs cockroachdb#114676

Release note (bug fix): Fixed a bug that could result in an internal error
when attempting to create a PL/pgSQL routine using the (currently unsupported)
`%ROWTYPE` syntax for a variable declaration.
craig bot pushed a commit that referenced this issue Apr 24, 2024
122660: plpgsql: avoid internal error when parsing variable type r=DrewKimball a=DrewKimball

Previously, when parsing the type of a declared PL/pgSQL variable, the parser could return an internal error when attempting to parse an expression like `xy@ROWTYPE`. This syntax, isn't currently supported in CRDB, but shouldn't result in an internal error, either. Now, the parser has inlined some logic from `GetTypeFromCastOrCollate` and will now return an expected syntax error instead.

Informs #114676

Release note (bug fix): Fixed a bug that could result in an internal error when attempting to create a PL/pgSQL routine using the (currently unsupported) `%ROWTYPE` syntax for a variable declaration.

Co-authored-by: Drew Kimball <drewk@cockroachlabs.com>
blathers-crl bot pushed a commit that referenced this issue Apr 24, 2024
Previously, when parsing the type of a declared PL/pgSQL variable, the
parser could return an internal error when attempting to parse an
expression like `xy@ROWTYPE`. This syntax, isn't currently supported in
CRDB, but shouldn't result in an internal error, either. Now, the parser
has inlined some logic from `GetTypeFromCastOrCollate` and will now return
an expected syntax error instead.

Informs #114676

Release note (bug fix): Fixed a bug that could result in an internal error
when attempting to create a PL/pgSQL routine using the (currently unsupported)
`%ROWTYPE` syntax for a variable declaration.
@DrewKimball DrewKimball changed the title plpgsql: internal error when attempting to use column/table type for variable plpgsql: support syntax to use column/table type for variable Apr 24, 2024
cockroach-dev-inf pushed a commit that referenced this issue Apr 24, 2024
Previously, when parsing the type of a declared PL/pgSQL variable, the
parser could return an internal error when attempting to parse an
expression like `xy@ROWTYPE`. This syntax, isn't currently supported in
CRDB, but shouldn't result in an internal error, either. Now, the parser
has inlined some logic from `GetTypeFromCastOrCollate` and will now return
an expected syntax error instead.

Informs #114676

Release note (bug fix): Fixed a bug that could result in an internal error
when attempting to create a PL/pgSQL routine using the (currently unsupported)
`%ROWTYPE` syntax for a variable declaration.
DrewKimball added a commit to DrewKimball/cockroach that referenced this issue Apr 25, 2024
Postgres allows using `%TYPE` and `%ROWTYPE` syntax to refer to the
type of a table or variable when declaring a PL/pgSQL variable. This is
currently unsupported in CRDB. This commit augments the error message
when a user attempts to use this syntax with a pointer to the tracking
issue.

Informs cockroachdb#114676

Release note: None
DrewKimball added a commit to DrewKimball/cockroach that referenced this issue Apr 25, 2024
Postgres allows using `%TYPE` and `%ROWTYPE` syntax to refer to the
type of a table or variable when declaring a PL/pgSQL variable. This is
currently unsupported in CRDB. This commit augments the error message
when a user attempts to use this syntax with a pointer to the tracking
issue.

Informs cockroachdb#114676

Release note: None
craig bot pushed a commit that referenced this issue Apr 25, 2024
123028: plpgsql: improve error message for %TYPE and %ROWTYPE syntax r=DrewKimball a=DrewKimball

Postgres allows using `%TYPE` and `%ROWTYPE` syntax to refer to the type of a table or variable when declaring a PL/pgSQL variable. This is currently unsupported in CRDB. This commit augments the error message when a user attempts to use this syntax with a pointer to the tracking issue.

Informs #114676

Release note: None

Co-authored-by: Drew Kimball <drewk@cockroachlabs.com>
blathers-crl bot pushed a commit that referenced this issue Apr 25, 2024
Postgres allows using `%TYPE` and `%ROWTYPE` syntax to refer to the
type of a table or variable when declaring a PL/pgSQL variable. This is
currently unsupported in CRDB. This commit augments the error message
when a user attempts to use this syntax with a pointer to the tracking
issue.

Informs #114676

Release note: None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. docs-known-limitation docs-todo O-qa P-3 Issues/test failures with no fix SLA T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

3 participants