Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Handling Nulls in ARRAY_AGG
00:00
5 left

Handling Nulls in ARRAY_AGG

MediumSQL · PostgreSQL

Problem

How do you handle null values when using the ARRAY_AGG function in BigQuery?

Using PostgreSQL, write a query against products and product_attributes that treats NULL attribute values as absent and returns an empty text array when no non-null values exist.

Output

  1. One row per product with product_id, product_name, and attribute_values
  2. Include every product, order values alphabetically within each array, and sort rows by product_id

Schema

products
ColumnTypeDescription
product_idPKINTUnique product identifier
product_nameVARCHAR(100)Product display name
product_attributes
ColumnTypeDescription
attribute_idPKINTUnique attribute record identifier
product_idINTProduct associated with the attribute
attribute_valueVARCHAR(100)Optional descriptive attribute value
Tablesproductsproduct_attributes
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.