In AWS Redshift, I am using json_extract_path_text function to parse simple Json.
I deliberately try to find non exists element in the Json so the function should return NULL.
If I use the function in ‘standalone’ select, the function return NULL as expected but if the function is used in select from table then a string empty ("") returned.
Here a simple example:
select json_extract_path_text('{"A":"B"}', 'AA'); --> Return NULL as expected.
create table #test (
payload varchar(max)
);
insert into #test (payload) values ('{"A":"B"}');
select json_extract_path_text(payload,'AA') from #test; --> Return empty string
How can I make the function return null from select table query?
Thanks.
I try everything…
2
Answers
I posted to AWS the issue and they approved that this is a bug in Redshift: AWS support: "I have been in contact with our internal team and they mentioned that the inconsistency is actually a bug from Redshift side that is still being worked on by the Service team and will be addressed in the upcoming patches"
You need to use the
NULLIF
function