public inbox for [email protected]  
help / color / mirror / Atom feed
Having issues inserting a string with a ' into a varchar column
4+ messages / 3 participants
[nested] [flat]

* Having issues inserting a string with a ' into a varchar column
@ 2022-04-15 18:01 Sbob <[email protected]>
  2022-04-15 18:02 ` Re: Having issues inserting a string with a ' into a varchar column Sbob <[email protected]>
  2022-04-15 18:16 ` Re: Having issues inserting a string with a ' into a varchar column David G. Johnston <[email protected]>
  2022-04-15 22:11 ` Re: Having issues inserting a string with a ' into a varchar column Gavan Schneider <[email protected]>
  0 siblings, 3 replies; 4+ messages in thread

From: Sbob @ 2022-04-15 18:01 UTC (permalink / raw)
  To: Pgsql-admin <[email protected]>

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...


Thanks in advance




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Having issues inserting a string with a ' into a varchar column
  2022-04-15 18:01 Having issues inserting a string with a ' into a varchar column Sbob <[email protected]>
@ 2022-04-15 18:02 ` Sbob <[email protected]>
  2 siblings, 0 replies; 4+ messages in thread

From: Sbob @ 2022-04-15 18:02 UTC (permalink / raw)
  To: Pgsql-admin <[email protected]>

correction, the quote_ident below should be quote_literal

I did not try quote_ident




On 4/15/22 12: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...
>
>
> Thanks in advance
>
>
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Having issues inserting a string with a ' into a varchar column
  2022-04-15 18:01 Having issues inserting a string with a ' into a varchar column Sbob <[email protected]>
@ 2022-04-15 18:16 ` David G. Johnston <[email protected]>
  2 siblings, 0 replies; 4+ messages in thread

From: David G. Johnston @ 2022-04-15 18:16 UTC (permalink / raw)
  To: Sbob <[email protected]>; +Cc: Pgsql-admin <[email protected]>

On Friday, April 15, 2022, Sbob <[email protected]> wrote:
>
> 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:
>
>
You have the right idea you need to escape it.  But guessing isn’t a good
method to figure out how.

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

You can’t use quote_* on a literal if you do not express the literal
correctly.

David J.


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Having issues inserting a string with a ' into a varchar column
  2022-04-15 18:01 Having issues inserting a string with a ' into a varchar column Sbob <[email protected]>
@ 2022-04-15 22:11 ` Gavan Schneider <[email protected]>
  2 siblings, 0 replies; 4+ messages in thread

From: Gavan Schneider @ 2022-04-15 22:11 UTC (permalink / raw)
  To: Pgsql-admin <[email protected]>; +Cc: Sbob <[email protected]>

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


^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2022-04-15 22:11 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-04-15 18:01 Having issues inserting a string with a ' into a varchar column Sbob <[email protected]>
2022-04-15 18:02 ` Sbob <[email protected]>
2022-04-15 18:16 ` David G. Johnston <[email protected]>
2022-04-15 22:11 ` Gavan Schneider <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox