This is my query
select object_construct('id', id, alpha, PARSE_JSON(null)) from tablename limit 1
the output is { "id" :1, "alpha":null }
but when I combined parse_json with ifnull it returns empty object {} not working as expected
select object_construct('id',IFNULL(id, (PARSE_JSON(null)), alpha, IFNULL(alpha, (PARSE_JSON(null))) from tablename limit 1
the above returns {}
but I need to have the null values { "id" : 1, "alpha" : null }
combining is not working any solutions?
[Question Updated]
Thanks Felipe Hoffa.
In Your answer, the last part is working as expected.
SELECT OBJECT_CONSTRUCT('id', id, 'alpha', IFNULL(alpha, PARSE_JSON('null')))
FROM (SELECT 1 id, null alpha)
# {"alpha": null, "id": 1}
But When I try with the below, it is not Working
SELECT OBJECT_CONSTRUCT(
'id', id,
'alpha', IFNULL(alpha, PARSE_JSON('null'))
)
FROM (SELECT id, alpha from tableName)
#{ "id" :1 }
it works, when using your FROM query : FROM (SELECT 1 id, null alpha)
not working, when using my FROM query : FROM (SELECT id, alpha from tableName)
Hope cleared.
Thanks in Advance