Hey Everyone

Hope you are doing well

I am trying to compare structs with structs using the IN clause. Here is
what I found.
The following query comparing structs gives error

SELECT struct(1, 2) IN (
SELECT struct(c1, c2)
FROM (VALUES (1, 2), (3, 4)) AS t(c1, c2)
);

Error - Cannot resolve "(named_struct('1', 1, '2', 2) IN (listquery()))"
due to data type mismatch: The number of columns in the left hand side of
an IN subquery does not match the number of columns in the output of
subquery. *Left hand side columns(length: 2)*: ["1", "2"], *right hand side
columns(length: 1)*: ["struct(c1, c2)"]. However, if I specify named_struct
instead of a struct, then it works fine.

SELECT named_struct('1', 1, '2', 2) IN (
SELECT struct(c1, c2)
FROM (VALUES (1, 2), (3, 4)) AS t(c1, c2)
);

+--------------------------------------------------------------+
| (named_struct(1, 1, 2, 2) IN (listquery())) |
+--------------------------------------------------------------+
|                                       true |
+--------------------------------------------------------------+ What is
happening here? Thanks & Regards Dhruv

Reply via email to