Skip to content
Advertisement

Passing tuples to SQL query while unnesting

I need to query a large BigQuery table to retrieve data from certain dates about barcodes in a store. There is a specified date for each of these barcodes (there are thousands of dates for each barcode in the BigQuery table, which makes it unpractical to only query on barcode). I have therefore created a list of tuples containing the barcodes and specific dates (only a very small subset):

My query today looks like this:

This obviously doesn’t work since it will take all the possible combinations of barcodes and dates. I only want the combinations that match the list I have.

I tried this

and

None worked!

I would be grateful for hints on how to solve this.

Advertisement

Answer

You might consider using tuple syntax in your query.

(barcode, date) IN UNNEST(date_and_barcode)

Query results

enter image description here


Python Example

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement