skip to Main Content

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

enter image description here

enter image description here

How can I make the function return null from select table query?
Thanks.

I try everything…

2

Answers


  1. Chosen as BEST ANSWER

    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"


  2. You need to use the NULLIF function

    select nullif(json_extract_path_text(payload,'AA'),'') from #test
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search