0

I am getting a JSON response from a server, in order to arrange and clean the data I am restructuring the response. When I send the data back to a Postgresql DB, I get an error for entries like place's

I understand that in SQL it should be written as place''s and not as place\'s

How can I load and work with JSON data without changing this property?

For example, I am trying the following query:

INSERT INTO table_name VALUES (111, 'name', "Dana place's")

As it interpreted by PostgreSQL into Dana place/'s

gbox
  • 809
  • 1
  • 8
  • 22
  • Instead of single quotes use [dollar quoting](https://stackoverflow.com/questions/12144284/what-are-used-for-in-pl-pgsql) (see the accepted answer) or the [documentation](https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS). – Stefanov.sm Dec 06 '21 at 14:31
  • @Stefanov.sm f"$$value$$" leaves the entry with the dollar signs in the DB – gbox Dec 06 '21 at 15:42
  • No, dollar-quote the _whole_ query text 'as is' w/o touching the single quotes. – Stefanov.sm Dec 06 '21 at 15:48
  • you can use the `quote_nullable()` function see the [manual](https://www.postgresql.org/docs/14/functions-string.html) – Edouard Dec 06 '21 at 16:20
  • @Stefanov.sm `f"$$INSERT INTO table_name VALUES (111, 'name', "Dana place's") $$"`? – gbox Dec 06 '21 at 16:32
  • Sorry, my suggestion is wrong. Pls. ignore it. – Stefanov.sm Dec 06 '21 at 17:23

0 Answers0