cockroachdb / cockroachdb/cockroach

sql: cannot cast to pseudo types such as any and anyelement

Open
#151,178 0 comments 0 reactions 0 assignees View on GitHub
A-sql-pgcompat A-sql-typing C-enhancement O-qa T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

(Thanks to @paulniziolek for finding this!)

PostgreSQL allows casts to pseudo-types such as `any`, `anyelement`, etc. I'm not sure what the utility is, but here are some examples:

```sql
SELECT 'a'::"any";
SELECT 1::"any";
SELECT 2.5::anyelement;
SELECT true::anyelement;
```

CockroachDB does not allow these casts:

```
demo@127.0.0.1:26257/demoapp/defaultdb> SELECT 'a'::"any";
ERROR: invalid cast: string -> any
SQLSTATE: 42846
demo@127.0.0.1:26257/demoapp/defaultdb> SELECT 1::"any";
ERROR: invalid cast: int -> any
SQLSTATE: 42846
demo@127.0.0.1:26257/demoapp/defaultdb> SELECT 2.5::anyelement;
ERROR: invalid cast: decimal -> anyelement
SQLSTATE: 42846
demo@127.0.0.1:26257/demoapp/defaultdb> SELECT true::anyelement;
ERROR: invalid cast: bool -> anyelement
SQLSTATE: 42846
```

Jira issue: CRDB-53103

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.