cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.06k stars 3.8k forks source link

"VALUES types decimal and int cannot be matched" when mixing integer and numeric literals #132165

Open lukaseder opened 2 weeks ago

lukaseder commented 2 weeks ago

Describe the problem

When using the VALUES constructor mixing integer and numeric literals, there's an error:

SQL Error [42804]: ERROR: VALUES types decimal and int cannot be matched

To Reproduce

values 
  (1), 
  (1.1), 
  (1.10);

Expected behavior

I'd expect the integer to be widened automatically to numeric, just like when it is too large to fit in an integer anyway, e.g. this works:

values 
  (1000000000000000000000000000000), 
  (1.1), 
  (1.10);

E.g. PostgreSQL handles this

Environment:

Workarounds

Avoid the implicit data types with casts:

values 
  (cast(1 as numeric)), 
  (1.1), 
  (1.10);

Or turn the value into a numeric literal:

values 
  (1E0), -- also 1.0
  (1.1), 
  (1.10);

Use union instead:

select 1
union all
select 1.1
union all
select 1.10

Jira issue: CRDB-42860

blathers-crl[bot] commented 2 weeks ago

Hi @lukaseder, please add branch-* labels to identify which branch(es) this C-bug affects.

:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

blathers-crl[bot] commented 2 weeks ago

Hello, I am Blathers. I am here to help you get the issue triaged.

Hoot - a bug! Though bugs are the bane of my existence, rest assured the wretched thing will get the best of care here.

I was unable to automatically find someone to ping.

If we have not gotten back to your issue within a few business days, you can try the following:

:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.