简体   繁体   中英

Big Query - Asserts with CTEs?

Is there a way to insert an 'assert' in the query below? (incorrect syntax)

WITH 

NAMES as ( SELECT 'Joe' as boy, 'Laura' as girl )

ASSERT SELECT boy FROM NAMES != 'Karl' as 'Invalid name' 

SELECT * FROM NAMES

If you don't mind adding on more column, then you can do:

WITH 

NAMES as ( SELECT 'Joe' as boy, 'Laura' as girl )

SELECT *, IF(boy = 'Karl', Error('Invalid name'), NULL) AS asserts FROM NAMES

If you do, you can exclude the column like:

SELECT * EXCEPT(asserts) FROM (

WITH 

NAMES as ( SELECT 'Joe' as boy, 'Laura' as girl )

SELECT *, IF(boy = 'Joe', Error('Invalid name'), NULL) AS asserts FROM NAMES

)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM