• saqibOP
    link
    fedilink
    English
    arrow-up
    1
    ·
    21 days ago

    Using the Spread Operator in the WHERE clause:

    create or replace table customers (id int, name string);
    INSERT INTO customers (id, name) VALUES
      (1, 'Saqib'), (2, 'Ali'), (3, 'Uroosa')
      , (4, 'Maryam'), (5, 'Fatima'), (6, 'Alia') ;
    
    -- We want the customer IDs 1, 3 and 6, where these ids are in an array i.e. [1,3,6]
    -- Now we can use the Spread Operator in the WHERE clause as following
    
    SELECT *
    FROM customers
    where ID IN (** [1, 3, 6]) --> Expanding an ARRAY [1,3,6] using the Spread Operator;
    

    Output:

    id name
    1 Saqib
    3 Uroosa
    6 Alia