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

float and int unsupported binary operator #82478

Open
kocoten1992 opened this issue Jun 6, 2022 · 5 comments
Open

float and int unsupported binary operator #82478

kocoten1992 opened this issue Jun 6, 2022 · 5 comments
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. E-starter Might be suitable for a starter project for new employees or team members. O-community Originated from the community T-sql-queries SQL Queries Team

Comments

@kocoten1992
Copy link

kocoten1992 commented Jun 6, 2022

Describe the problem

Here is a simple reproduction

# postgres
select 8::float / 8::int;
 ?column? 
----------
        1
(1 row)
# cockroachdb
select 8::float / 8::int;
ERROR: unsupported binary operator: <float> / <int>
SQLSTATE: 22023

(I'm deleting all old content for brevity because it all boil down to the reproduction above, you can check back via github history log)

Jira issue: CRDB-16414

@kocoten1992 kocoten1992 added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Jun 6, 2022
@blathers-crl
Copy link

blathers-crl bot commented Jun 6, 2022

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:

  • Join our community slack channel and ask on #cockroachdb.
  • Try find someone from here if you know they worked closely on the area and CC them.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@blathers-crl blathers-crl bot added O-community Originated from the community X-blathers-untriaged blathers was unable to find an owner labels Jun 6, 2022
@blathers-crl blathers-crl bot added the T-sql-queries SQL Queries Team label Jun 6, 2022
@yuzefovich yuzefovich removed X-blathers-untriaged blathers was unable to find an owner T-sql-queries SQL Queries Team labels Jun 6, 2022
@kocoten1992
Copy link
Author

kocoten1992 commented Jun 6, 2022

Okay, so I'm missing one final cast float at:

WITH RECURSIVE per_investor_amount AS (
  SELECT 0::int AS investors_number, 0.00::float AS investment_amount, 0.00::float AS individual_amount
  UNION
  SELECT (investors_number + 1)::int, i.investment_amount, i.investment_amount / (investors_number + 1)::float /* HERE */
  FROM investment i, per_investor_amount pia WHERE investors_number < 3
)
SELECT * FROM per_investor_amount ORDER BY investment_amount, investors_number;
# cockroachdb
  investors_number | investment_amount |   individual_amount
-------------------+-------------------+-------------------------
                 0 |                 0 |                      0
                 1 | 5.322146e+06      | 5.322146e+06
                 2 | 5.322146e+06      | 2.661073e+06
                 3 | 5.322146e+06      | 1.7740486666666667e+06
                 1 | 5.6129486e+06     | 5.6129486e+06
                 2 | 5.6129486e+06     | 2.8064743e+06
                 3 | 5.6129486e+06     | 1.8709828666666665e+06
                 1 | 9.705321e+06      | 9.705321e+06
                 2 | 9.705321e+06      | 4.8526605e+06
                 3 | 9.705321e+06      | 3.235107e+06
(10 rows)

Still not sure if this is a bug (given postgres work?).

@kocoten1992 kocoten1992 changed the title cte recursive incorrect type assumption? float and int unsupported binary operator Jun 6, 2022
@kocoten1992
Copy link
Author

Hi @yuzefovich, I see you triage this, I've an update in reproduction (also updated the first post):

# postgres
select 8::float / 8::int;
 ?column? 
----------
        1
(1 row)
# cockroachdb
select 8::float / 8::int;
ERROR: unsupported binary operator: <float> / <int>
SQLSTATE: 22023

@blathers-crl blathers-crl bot added the T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) label Jun 6, 2022
@rafiss rafiss added the E-starter Might be suitable for a starter project for new employees or team members. label Aug 10, 2022
@rafiss
Copy link
Collaborator

rafiss commented Aug 10, 2022

I think #38965 and #75101 would solve this, but in the meantime we should be able to explicitly add float/int overloads.

@surahman
Copy link
Contributor

Hi @rafiss, could you please provide some context on where to look in the code base to get started with adding the explicit overloads? I have been out of code base for a while.

@rafiss rafiss added T-sql-queries SQL Queries Team and removed T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) labels May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. E-starter Might be suitable for a starter project for new employees or team members. O-community Originated from the community T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

4 participants