'How to write select query which matches data from a static array?

I have an array of strings for example ["1234", "3432", "3423", "3442"]

I want to select all records of a table whose ID matches values from this static array.

Please help me with the query.



Solution 1:[1]

Try this way:

SELECT number AS id
FROM numbers(5000)
WHERE id IN 
(
    WITH
        ['1234', '3432', '3423', '3442'] AS ids,
        arrayMap(x -> toInt32(x), ids) AS number_ids
    SELECT arrayJoin(number_ids)
)

/*
????id??
? 1234 ?
? 3423 ?
? 3432 ?
? 3442 ?
????????
*/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 vladimir