question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bigquery: Expecting unordered_sql, found "UNPIVOT IN"

See original GitHub issue

Hi my friend!

We found that error when BQ query: Expecting unordered_sql, found "UNPIVOT IN" (at char 129), (line:8, col:9)

WITH
shift_history_pivoted as (
    SELECT * FROM `*********************.**************.**************`)
        UNPIVOT INCLUDE NULLS (
            status FOR time_interval IN (
                x0h00m_0h30m,
                x0h30m_1h00m,
                x1h00m_1h30m,
                x1h30m_2h00m,
                x2h00m_2h30m,
                x2h30m_3h00m,
                x3h00m_3h30m,
                x3h30m_4h00m,
                x4h00m_4h30m,
                x4h30m_5h00m,
                x5h00m_5h30m,
                x5h30m_6h00m,
                x6h00m_6h30m,
                x6h30m_7h00m,
                x7h00m_7h30m,
                x7h30m_8h00m,
                x8h00m_8h30m,
                x8h30m_9h00m,
                x9h00m_9h30m,
                x9h30m_10h00m,
                x10h00m_10h30m,
                x10h30m_11h00m,
                x11h00m_11h30m,
                x11h30m_12h00m,
                x12h00m_12h30m,
                x12h30m_13h00m,
                x13h00m_13h30m,
                x13h30m_14h00m,
                x14h00m_14h30m,
                x14h30m_15h00m,
                x15h00m_15h30m,
                x15h30m_16h00m,
                x16h00m_16h30m,
                x16h30m_17h00m,
                x17h00m_17h30m,
                x17h30m_18h00m,
                x18h00m_18h30m,
                x18h30m_19h00m,
                x19h00m_19h30m,
                x19h30m_20h00m,
                x20h00m_20h30m,
                x20h30m_21h00m,
                x21h00m_21h30m,
                x21h30m_22h00m,
                x22h00m_22h30m,
                x22h30m_23h00m,
                x23h00m_23h30m,
                x23h30m_0h00m
            )
)

SELECT
    id,
    membros,
    canal_de_atendimento,
    status,
    department,
    dia_da_semana,
    data,
    time_interval,
    created_date,
    last_modified_date,
    synced_at
FROM
    nu_com_a_mao_no_bolso
WHERE
    time_interval IS NOT NULL

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
klahnakoskicommented, Dec 8, 2022

i simplified the query to

    WITH
        shift_history_pivoted as (
            SELECT * FROM `*********************.**************.**************`)
                UNPIVOT INCLUDE NULLS (
                    status FOR time_interval IN (
                        x0h00m_0h30m,
                        x0h30m_1h00m
                    )
        )            
        SELECT
            id
        FROM
            nu_com_a_mao_no_bolso
        WHERE
            time_interval IS NOT NULL

which did not compile. But moving the close brace fixed the problem:

image

The resulting SQL will compile

    WITH
        shift_history_pivoted as (
            SELECT * FROM `*********************.**************.**************` 
                UNPIVOT INCLUDE NULLS (
                    status FOR time_interval IN (
                        x0h00m_0h30m,
                        x0h30m_1h00m
                    )
                )
        )            
        SELECT
            id
        FROM
            nu_com_a_mao_no_bolso
        WHERE
            time_interval IS NOT NULL
0reactions
klahnakoskicommented, Dec 10, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to unpivot in BigQuery? - Stack Overflow
A new UNPIVOT operator has been introduced into BigQuery. Before UNPIVOT is used to rotate Q1, Q2, Q3, Q4 into sales and quarter...
Read more >
Query syntax | BigQuery - Google Cloud
The UNION operator combines the result sets of two or more input queries by pairing columns from the result set of each query...
Read more >
Pivot and Unpivot Functions in BigQuery For Better Data ...
Pivot is a very simple function in BigQuery that can be very useful when you need to rotate rows into columns. It uses...
Read more >
Using BigQuery's new (UN)PIVOT and QUALIFY Features with ...
This article will look into utilizing PIVOT and QUALIFY with the Google Analytics 4 export data in BigQuery. With Google Analytics 4, the...
Read more >
BigQuery Columns to Rows: Using Pivot & Unpivot Operators ...
Pivot and Unpivot are Relational Operators used to transform one table into another in order to obtain a more simplified view of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found