Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spanner DB query on Array type column

I wanted to write a select query to fetch all the records but I am getting error if I try to match more than one type against a array type column, for example Below query is working

SELECT * FROM Car where ("Ford") IN UNNEST (cartype)

But this query is failing

SELECT * FROM Car where (["Ford","Honda","Suzuki"]) IN UNNEST (cartype)

HTTPError 400: {"code":3, "message":"First argument to IN UNNEST of type ARRAY does not support equality comparison [at 1:42]\

like image 327
sKarwasra Avatar asked Jun 23 '26 21:06

sKarwasra


1 Answers

I have tried this on my end i got the same error when i tried with below query

SELECT * FROM Car where (["Ford","Honda","Suzuki"]) IN UNNEST (cartype)

Instead of the ARRAY\_INCLUDES function as answered by @Knut Olav Løite you can use the below query as well.

SELECT * FROM Car where (cartype) IN UNNEST  (["Ford","Honda","Suzuki"]) 

In above I have changed the query where comparing the array column cartype with an array literal (["Ford","Honda","Suzuki"])

UNNEST operator converts an array to a table. Here cartype is a table column in which these UNNEST values may appear.

like image 101
Sathi Aiswarya Avatar answered Jul 01 '26 07:07

Sathi Aiswarya