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()
Postgres allows PLpgSQL variable declarations to inherit the type of a table row or column using special syntax (docs):
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:Jira issue: CRDB-33620