I have in the database a table query_config, which will contain scripts for querying, as well as other configuration values. This is the reason why I use json type. Table as follows:
CREATE TABLE query_config
(
id integer,
execute_query json
);
In this table I want to insert eg:
INSERT INTO query_config(id, execute_query)
VALUES (4, ('{"query": ' ||
'"select *
from tests
where tests.id > 5
order by moment desc"}')::json);
But I keep getting the error:
ERROR: invalid input syntax for type json
DETAIL: Character with value 0x0a must be escaped.
What am I doing wrong please and how do I escape newline character?