questdb icon indicating copy to clipboard operation
questdb copied to clipboard

SQL: Join Column Type Mismatch

Open ideoma opened this issue 4 years ago • 21 comments

Describe the bug

When 2 tables joined on INT and LONG columns error shown that there is join column mismatch

To reproduce

select x, y
from long_sequence(100) ls
join (
  select cast(x as int) y from long_sequence(100)
) as ls2
on ls.x = ls2.y

Expected Behavior

INT can be be upcast to LONG and equality should be checked as LONG equality so that above query returns 100 rows

Environment

- **QuestDB version**: 6.1.2
- **OS**: any
- **Browser**: any

Additional context

Comparing mixed data types works for many numeric types in WHERE. Same should be in JOIN condition

ideoma avatar Dec 13 '21 22:12 ideoma

`When 2 tables joined on INT and LONG columns error shown that there is join column mismatch

select x, y from long_sequence(100) ls join ( select x ,y from long_sequence(100) ) as ls2 on CAST(ls.x as int)= ls2.y`

amankothiyal04 avatar Jan 23 '22 11:01 amankothiyal04

`When 2 tables joined on INT and LONG columns error shown that there is join column mismatch

select x, y from long_sequence(100) ls join ( select x ,y from long_sequence(100) ) as ls2 on CAST(ls.x as int)= ls2.y`

Will this resolve the issue?

amankothiyal04 avatar Jan 23 '22 11:01 amankothiyal04

I am interested in working on this issue if still available

kitsiosvas avatar Jan 26 '22 23:01 kitsiosvas

I would like to work on this if it's still available

mchirag2002 avatar Mar 07 '22 07:03 mchirag2002

What's the status of this issue? I'd like to work on it!

zly7 avatar Mar 21 '22 12:03 zly7

@zhangliyuSustech I don't think someone is working on this one, so your contribution is highly welcome. 👍

puzpuzpuz avatar Mar 21 '22 12:03 puzpuzpuz

I have scheduled this issue, I will try my best to fix it in three weeks.

zly7 avatar Mar 22 '22 10:03 zly7

I think this issue is beyond my ability, but I will continuously pay attention to it and discuss with my classmates for solution.

zly7 avatar Apr 11 '22 07:04 zly7

No problem. Thanks for letting us now .

bziobrowski avatar Apr 11 '22 07:04 bziobrowski

Hi, what's the status of this issue? I'd like to work on it if it's still open.

XinyiQiao avatar Jun 16 '22 17:06 XinyiQiao

Hi @XinyiQiao , thank you very much for offering help!! another T-shirt in the horizon :) You are very welcome to work on the issue, we have assigned it to you. Have a lot of fun!!

marregui avatar Jun 23 '22 08:06 marregui

I would like to work on this issue.

rajdeepdas2000 avatar Sep 11 '22 12:09 rajdeepdas2000

You receive a column mismatch error due to comparing incompatible data types. Upcasting and int to a long can be done using the data types BIGint instead. This would allow enough bytes in this data type to compare to a long. The new code is shown below:

select x, y from long_sequence(100) ls join ( select cast(x as BIGint) y from long_sequence(100) ) as ls2 on ls.x = ls2.y

When I run this code in QuestDB the table displays 100 rows with the same values for both the x and y columns. No mismatch error occurs.

QuestDB version: [10:26:50]

eggman2532 avatar Mar 25 '23 14:03 eggman2532

Hye assigned me this issue want to work on this

shraddha761 avatar Apr 14 '23 08:04 shraddha761

it seems like there is a type mismatch error when joining two tables on an INT and a LONG column.

The query is attempting to join the "x" column from a table generated using the "long_sequence" function, with the "y" column from a subquery that casts the "x" column to an INT.

The expected behavior is that the INT value in the subquery should be upcast to LONG and compared to the LONG value in the other table. This should result in the query returning 100 rows.

However, the current behavior is that an error is shown indicating a join column mismatch, which suggests that the query is not correctly handling the type conversion.

This issue seems to be specific to the QuestDB database version 6.1.2. It is possible that this issue has been fixed in a later version of QuestDB or may require a different syntax to achieve the desired behavior.

Sidopolis avatar Apr 16 '23 14:04 Sidopolis

I am interested in working on this issue if still available

Jatingupta9120 avatar Apr 17 '23 17:04 Jatingupta9120

Based on your description, it sounds like you expect the join to work by casting the INT column to a LONG column and then performing the join. However, it appears that this is not currently possible in QuestDB.

One potential workaround for this issue could be to cast both columns to a common data type that is compatible with both INT and LONG. For example, you could cast both columns to a DOUBLE or a DECIMAL type before joining them. This should allow the join to work as expected.

Another option could be to modify the data types of the columns in one or both tables so that they match. For example, you could change the INT column to a LONG column, or vice versa.

I Want to work on this assign me this issue please.

theNKCode avatar Apr 18 '23 02:04 theNKCode

Hi, I want to contribute to this issue. In this case, you are casting the "x" column of the "ls" table to "int" in the subquery, but you are still joining it with the "x" column of the "ls" table, which is of type "long". To fix this, you can change the alias of the "y" column in the subquery to "x" so that it matches the column name of the "ls" table and then cast the "x" column of the "ls" table to "long" in the join condition. Please Assign me this issue.

neeraj542 avatar Apr 18 '23 12:04 neeraj542

I have an updated query to resolve this issue: image

neeraj542 avatar Apr 18 '23 21:04 neeraj542

This query will return all pairs of values (x, y) where x is a number from 1 to 100 and y is the integer representation of x. The result set will contain 100 rows with x and y values ranging from 1 to 100.

Subha2727 avatar May 01 '23 15:05 Subha2727

can i work on this issue? can u provide path to the issue file?

ekafrancium avatar Jun 19 '23 13:06 ekafrancium