Re: Quoted strings on CLI

From: Alexander Reichstadt <lxr(at)mac(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Quoted strings on CLI
Date: 2012-03-02 10:05:49
Message-ID: F5ED7EDA-742B-43FA-AA24-93D63D89631A@mac.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks a lot, I use the '' approach, works for my case.

Regards

Am 02.03.2012 um 10:14 schrieb Pavel Stehule:

> Hello
>
> you cannot use a \ escaping when you have standard_conforming_strings enabled.
>
> There are four ways:
>
> first - use a usual way for using quotes - use a doubling single quotes
>
> postgres=# select 'Peter''s toy';
> ?column?
> ─────────────
> Peter's toy
> (1 row)
>
> or you can use a own string delimiters
>
> postgres=# select $$Peter's toy$$;
> ?column?
> ─────────────
> Peter's toy
> (1 row)
>
> or you can disable standard_conforming_strings
>
> postgres=# set standard_conforming_strings to off;
> SET
> postgres=# select 'Peter\'s toy';
> WARNING: nonstandard use of \' in a string literal
> LINE 1: select 'Peter\'s toy';
> ^
> HINT: Use '' to write quotes in strings, or use the escape string
> syntax (E'...').
> ?column?
> ─────────────
> Peter's toy
> (1 row)
>
> or you can use PostgreSQL enhanced strings
>
> postgres=# select E'Peter\'s toy';
> ?column?
> ─────────────
> Peter's toy
> (1 row)
>
> Regards
>
> Pavel Stehule
>
>
> 2012/3/2 Alexander Reichstadt <lxr(at)mac(dot)com>:
>> Hi,
>>
>> I just migrated from mysql and am running into an issue I found no solution for when researching. Using the web interface I can insert values that contain single-quotes. But using the CLI I found no way to select or insert single quotes:
>>
>> PetWork=# select * from persons where firstname='\'Peter\'';
>> Invalid command \'';. Try \? for help.
>> PetWork-# select * from persons where firstname='\\'Peter\\'';
>> Invalid command \. Try \? for help.
>> PetWork-# select * from persons where firstname='\\\'Peter\\\'';
>> Invalid command \. Try \? for help.
>> PetWork-# select * from persons where firstname='\\\\'Peter\\\\'';
>> Invalid command \. Try \? for help.
>> PetWork-# select * from persons where firstname='\\\\'Peter\\\\'';
>>
>> On different forums the solution suggested is to prepend backslashes. But it doesn't matter how many backslashes I prepend, it always fails. What does one have to do to achieve that?
>>
>> Thanks for any help
>>
>> --
>> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-general
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Vincent Veyron 2012-03-02 10:17:36 Re: Yearly date comparison?
Previous Message Pavel Stehule 2012-03-02 09:14:22 Re: Quoted strings on CLI