-1

@a_horse_with_no_name - Before you close it again !

I know this post - but it does not solve ! Insert text with single quotes in PostgreSQL (7 answers)


I want to insert text with singles quotes into Postgresql 12 database.

repmondb=# insert into TEST ("vorname#") values ('\'hans\'');
ungültige Anweisung \'');
Versuchen Sie \? für Hilfe.

or

repmondb-# insert into TEST ("vorname#") values (''hans'');
ERROR:  syntax error at or near "hans"
ZEILE 1: insert into TEST ("vorname#") values ('\'hans

The escaping with \ and with extra ' does not work.

Sven Kirsten
  • 478
  • 1
  • 8
  • 27
  • The [duplicate question](https://stackoverflow.com/questions/12316953/) **is** the answer for this and the answer to that question also solves your problem. The necessary syntax is clearly [documented](https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS) in the manual –  Mar 18 '20 at 22:18

1 Answers1

2

Double quotes:

insert into TEST ("vorname#") values ('''hans''');

Dollar quoted string:

insert into TEST ("vorname#") values ($$'hans'$$);

db<>fiddle demo

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275