finding strings with quotes

Started by Christine Pennerabout 15 years ago3 messagesgeneral
Jump to latest
#1Christine Penner
chris@fp2.ca

I'm trying to do a select to find on a char field that has a single
quote but getting errors. This is what I'm doing:

Select * from f_buildings where B_STRET_LNE_CON='BERLETT\'S ROAD'

The text I'm trying to find is BERLETT'S ROAD

If I do the same thing but have double quotes in the string instead of
single quotes this works.

--
Christine Penner
Ingenious Software
250-352-9495
chris@fp2.ca

#2Bosco Rama
postgres@boscorama.com
In reply to: Christine Penner (#1)
Re: finding strings with quotes

Christine Penner wrote:

I'm trying to do a select to find on a char field that has a single
quote but getting errors. This is what I'm doing:

Select * from f_buildings where B_STRET_LNE_CON='BERLETT\'S ROAD'

There are a couple of ways to do this in PG but the easiest and closest
to the standard is to use two quotes to insert a quote into a string.

Like this:
Select * from f_buildings where B_STRET_LNE_CON='BERLETT''S ROAD'

HTH

Bosco.

#3Alban Hertroys
dalroi@solfertje.student.utwente.nl
In reply to: Christine Penner (#1)
Re: finding strings with quotes

On 25 Feb 2011, at 21:45, Christine Penner wrote:

I'm trying to do a select to find on a char field that has a single quote but getting errors. This is what I'm doing:

Select * from f_buildings where B_STRET_LNE_CON='BERLETT\'S ROAD'

The text I'm trying to find is BERLETT'S ROAD

If I do the same thing but have double quotes in the string instead of single quotes this works.

You probably have set standard_conforming_strings to 'on'.
In that case you should either use:
SELECT E'BERLETT\'S ROAD';
SELECT 'BERLETT''S ROAD';
Or set standard_conforming_strings TO 'off', in which case you'll just get a warning.

Alban Hertroys

--
Screwing up is an excellent way to attach something to the ceiling.

!DSPAM:737,4d68cc3d11735859949296!