I am trying to manipulate a JSON with a single quote inside, and I am having some troubles:
1.- When I have a function, I cant pass as parameter a JSON string with a single quote inside: This is the function:
CREATE OR REPLACE FUNCTION public.give_me_text
(
IN text json
)
RETURNS JSON AS
$$
DECLARE
v_text varchar;
begin
RAISE NOTICE 'text: %', text;
v_text:=text || '- hello';
return v_text;
end
$$
LANGUAGE 'plpgsql';
By calling like this is working:
SELECT * FROM give_me_text
(
'{"es":"name 1","en":"name 2","de":"name 3","fr":"name 4","pt":"name 5"}'
);
But when I have got a single quote is not working:
SELECT * FROM give_me_text
(
'{"es":"nam'e 1","en":"name 2","de":"name 3","fr":"name 4","pt":"name 5"}'
);
2.- When I am tryhing to insert JSON value with Single quote inside, it is giving me the same error: This is working:
INSERT INTO public.my_columns VALUES ('{ "name": "Book the First", "author": { "first_name": "Bob", "last_name": "White" } }');
But this is not working:
INSERT INTO public.my_columns VALUES ('{ "name": "Book's the First", "author": { "first_name": "Bob", "last_name": "White" } }');
Any ideas how to escape this single quote? Thanks
''
– Dropping