cockroachdb / cockroachdb/cockroach
sql: allow casting a polymorphic routine parameter
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
Assessment
This issue has not been assessed yet.