denze-e7j2NUCollection Snapshot by Wallet
    Updated 2023-11-08
    -- forked from c117abba-b476-47b5-aebf-ad54cb177174

    WITH

    input_contracts AS (
    SELECT
    *
    FROM VALUES
    (lower('{{nft_contract_address}}'))
    AS data(nft_contract_address)
    WHERE data.nft_contract_address regexp '^0x[0-9a-fA-F]{40}$' -- check address is a valid format, i.e. starts with 0x and has 42 characters total
    )

    , input_time AS (
    SELECT
    CASE
    WHEN to_timestamp_ntz(data.snapshot_time) > date_trunc('minute', current_timestamp) THEN current_date + interval '1 day' - interval '1 second'
    ELSE date_trunc('minute', to_timestamp_ntz(data.snapshot_time))
    END AS snapshot_time
    FROM VALUES
    ('{{snapshot_time}}')
    AS data(snapshot_time)
    )

    , input_token_ids AS (
    SELECT distinct
    F.value AS input_token_ids_num
    , 'tid' || F.value || '_' AS input_token_ids_string
    FROM (
    SELECT
    SPLIT(data.input_token_id_list, '_') AS input
    FROM VALUES
    ('{{token_ids}}')
    AS data(input_token_id_list)
    ) i
    , Table(Flatten(i.input)) AS F
    Run a query to Download Data