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: allow casting a polymorphic routine parameter #123536

Open
DrewKimball opened this issue May 3, 2024 · 0 comments
Open

sql: allow casting a polymorphic routine parameter #123536

DrewKimball opened this issue May 3, 2024 · 0 comments
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL A-sql-routine UDFs and Stored Procedures C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) docs-known-limitation T-sql-queries SQL Queries Team

Comments

@DrewKimball
Copy link
Collaborator

DrewKimball commented May 3, 2024

Since there is no cast from polymorphic types to other types (for example, TEXT), CRDB currently returns an error during function creation for a case like the following:

root@localhost:26257/defaultdb> CREATE FUNCTION f(x ANYELEMENT) RETURNS TEXT AS $$ SELECT x::TEXT; $$ LANGUAGE SQL;
ERROR: invalid cast: anyelement -> string
SQLSTATE: 42846

Postgres, on the other hand, allows the function to be created and called:

postgres=# CREATE FUNCTION f(x ANYELEMENT) RETURNS TEXT AS $$ SELECT x::TEXT; $$ LANGUAGE SQL;
CREATE FUNCTION
postgres=# SELECT f('hello world'::TEXT);
      f
-------------
 hello world
(1 row)

We should fix this, either by propagating some context through SemaContext to make type-checking ignore polymorphic types in this case, or by always allowing casts from polymorphic types.

Jira issue: CRDB-38387

@DrewKimball DrewKimball added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-queries SQL Queries Team A-sql-routine UDFs and Stored Procedures labels May 3, 2024
@yuzefovich yuzefovich added A-sql-pgcompat Semantic compatibility with PostgreSQL docs-known-limitation labels May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL A-sql-routine UDFs and Stored Procedures C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) docs-known-limitation T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

2 participants