1

I'm trying to execute an UPDATE from a psql prompt. I want to change all instances of a country name from Cote d"Ivoire to Cote d'Ivoire (so the double quote becomes a single quote). My first attempt did nothing but change the psql prompt (notice the double quote between the database name and the pound character)...

database=# UPDATE address SET country = 'Cote d\'Ivoire' WHERE country = 'Cote D"Ivoire'; database"#

...so I escaped the double quote and got an error:

database=# UPDATE address SET country = 'Cote d\'Ivoire' WHERE country = 'Cote D\"Ivoire'; Invalid command \"Ivoire';. Try \? for help.

What am I doing wrong?

Update:

I used dollar-quoted string constants to achieve what I wanted:

database=# UPDATE address SET country = $$Cote d'Ivoire$$ WHERE country = $$Cote D"Ivoire$$; UPDATE 22

Rob Johansen
  • 5,076
  • 10
  • 40
  • 72

1 Answers1

0

If you're using escapes in strings, you need to use the escaped string syntax. Put a capital E before your single quote. See this thorough answer: https://stackoverflow.com/a/12320729/1413900

Community
  • 1
  • 1
Travis Well
  • 947
  • 10
  • 32