0

I'm a bit stuck with accessing a value in an object contained in a JSON array. I've tried UNNEST() to no avail. Adding OFFSET or ORDINAL did not work. It threw Array index 0 is out of bounds (overflow)

Here is the query:

SELECT d.dealid, associations.associatedvids FROM hs.deals as d 
WHERE associations.associatedvids is not null

enter image description here

Thank you

3
  • 1
    Your first id is not null. Try != '' in addition to the is not null Commented Feb 19, 2020 at 14:55
  • That was it! Thanks! Commented Feb 19, 2020 at 15:00
  • Can you think of any WHERE condition that will work with []. It seems that != '' still returns rows with []. No matching signature for operator != for argument types: STRUCT<value INT64>, STRING. Supported signatures: ANY != ANY at [2:7] IS NOT NULL does return some rows with []. Commented Feb 19, 2020 at 15:06

2 Answers 2

3

The issue was that some rows included an empty array []. I've added WHERE condition to remove such rows:

WHERE ARRAY_LENGTH(d.associations.associatedvids) >= 1
Sign up to request clarification or add additional context in comments.

Comments

0

An easier alternative: SAFE

SELECT [][OFFSET(0)]
# Array index 0 is out of bounds (overflow)


SELECT [][SAFE_OFFSET(0)]
# null

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.