Re: Having issues inserting a string with a ' into a varchar column

From: Gavan Schneider <list(dot)pg(dot)gavan(at)pendari(dot)org>
To: Pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Cc: Sbob <sbob(at)quadratum-braccas(dot)com>
Subject: Re: Having issues inserting a string with a ' into a varchar column
Date: 2022-04-15 22:11:27
Message-ID: E8ADA5A8-5742-4B3C-8E87-05E34AD43968@pendari.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On 16 Apr 2022, at 4:01, Sbob wrote:

> Hi all;
>
>
> I have a table that includes a varchar column.
>
> I am inserting some data and one of the strings = "Poker 5 card
> Hold'Em"
>
> as a straight string it errors out.
>
> I tried this :  quote_ident ( 'Poker 5 card Hold'Em')
>
> but it still error's out
>
>
> I also tried : quote_literal('Poker 5 card Hold\'Em')
>
> but it also errors out:
>
> psql:test.sql:1042: ERROR:  syntax error at or near "Em"
> LINE 1: ...ed) VALUES ( quote_literal('Poker 5 card Hold\\'Em'), 2,
> 1...
>
Unbalanced single quote, try dollar quotes as a general get out of jail
approach…

pendari=# SELECT $x$Poker 5 card Hold'Em$x$::TEXT;
text
----------------------
Poker 5 card Hold'Em
(1 row)

https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS

Regards

Gavan Schneider
——
Gavan Schneider, Sodwalls, NSW, Australia
Explanations exist; they have existed for all time; there is always a
well-known solution to every human problem — neat, plausible, and
wrong.
— H. L. Mencken, 1920

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Bhupendra Babu 2022-04-16 04:14:25 Re: postgresql-14 slow query
Previous Message Doug Reynolds 2022-04-15 22:10:33 Re: postgresql-14 slow query