08-22-2025 10:19 AM
This is what I'm trying to do using SQL:
08-22-2025 12:16 PM
Root Cause
That’s why you see the error
Solution:
Try Using array_contains to structure your query.
Use array_contains
If you’re filtering using an array variable:
DECLARE ids ARRAY<STRING>;
SET VARIABLE ids = ARRAY('12483258','12483871','12483883');
CREATE TABLE check1 AS
SELECT *
FROM dataA
WHERE array_contains(ids, IDs);
08-22-2025 10:46 AM
Hi @,
This is expected. Your id column is of type string and you're trying to provide in in clause array<string>
08-22-2025 10:55 AM
Thanks for responding. So what's the proper way of using an array there?
08-22-2025 11:12 AM
I don't have access to computer right now, but I'll provide you tomorrow code that should work
08-22-2025 11:54 AM
Hi @zc,
I managed to reproduce your scenario and put together a possible solution—see if it helps.
Simulating the error:
Solution with array:
08-22-2025 01:20 PM
Thank you for this, your solution works but in a different way. I've actually been using temp views in the same way, but that requires extra steps that's why I wanted to go for variables instead. But thank you for putting this together!
08-22-2025 12:16 PM
Root Cause
That’s why you see the error
Solution:
Try Using array_contains to structure your query.
Use array_contains
If you’re filtering using an array variable:
DECLARE ids ARRAY<STRING>;
SET VARIABLE ids = ARRAY('12483258','12483871','12483883');
CREATE TABLE check1 AS
SELECT *
FROM dataA
WHERE array_contains(ids, IDs);
08-22-2025 01:18 PM - edited 08-22-2025 01:20 PM
Thank you so much for your detailed explanation and perfect solution!
08-23-2025 05:44 AM
Nice solutions! @ManojkMohan @WiliamRosa
I love the use of the temp view for the intermediate result. The array_contains is also a really nice touch.
@ManojkMohan when you write "SET VARIABLE ids = ARRAY('12483258','12483871','12483883');" ... can this array be from another query to make it dynamic?
Really cool stuff.
@zc I guess we could also use parameters: https://docs.databricks.com/aws/en/sql/user/queries/query-parameters#query-based-dropdown-list . The benefit of this is that the query can be maintained/updated outside of the script, given that you used a query based drop down list parameter. I haven't tried it but it makes sense, in theory. Example of using a parameter below:
All the best,
BS
a month ago
Thank you for responding. Yeah I guess that's an option too. Talking about a list maintained outside of the script though, I'd prefer having a csv and import it as a temp view when needed.
Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!
Sign Up Now