BigQuery嵌套记录INSERT语句执行失败求助:请求排查问题原因
Fixing Your BigQuery INSERT Statement Issue
Hey there! Let's break down what's causing your INSERT statement to fail and how to fix it.
Key Problems in Your Original SQL
- Unnecessary alias in VALUES clause: You added
as nameafter'my_name'—this isn't needed here. TheINSERT INTOclause already defines the column order, so the VALUES list just needs to pass the values in that exact sequence without extra aliases. - Potential type/structure mismatch (double-check): Make sure your
addresscolumn intest_tableis defined asARRAY<STRUCT<line1 STRING, line2 STRING, code INT64>>. If the table's struct fields have different names (e.g.,line_1instead ofline1) or data types (e.g.,codeas a string), you'll still get errors even after fixing the syntax.
Corrected INSERT Statement
INSERT INTO `my_project.my_dataset.test_table`(name, address, comments) VALUES( 'my_name', [STRUCT('ABC' AS line1, 'XYZ' AS line2, 10 AS code), STRUCT('PQR' AS line1, 'STU' AS line2, 20 AS code)], 'Comment' );
Quick Explanation
- We removed the redundant
as namefrom the first value—this was causing a syntax error because BigQuery doesn't expect column aliases inside the VALUES list. - The struct array part is correctly formatted, but double-verify it matches your table's schema exactly. For example, if your table's
addressstruct useszip_codeinstead ofcode, you'll need to adjust the STRUCT definition to match that field name.
内容的提问来源于stack exchange,提问作者Dinesh
相关产品推荐
相关产品推荐

