473,395 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Help please - completely baffled by quoting

Hi,

I generally consider myself competent with the complexities of quoting but I
can't figure out postgres at all. I've read the manual and it looks very
straightforward but that doesn't accord with my experiences. Here's an
example:

create table temp (a varchar(50));
insert into temp values 'a\'b';
insert into temp values 'a\\b';
insert into temp values 'a\\\'b';

select * from temp returns
a'b
a\b
a\'b

so far so good but what about this:

select * from temp where a like 'a\\\'%'

this should return all strings starting with a\' but it returns nothing!!!

I would expect that these two

select * from temp where a like 'a\\\'b'
select * from temp where a = 'a\\\'b'

should return the same thing. The second one works as expected, but the
first one doesn't return anything.

I'm sure I'm missing something obvious. Thanks in advance for any help.

--- Tim

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #1
4 1272
Tim Robinson wrote:
select * from temp where a like 'a\\\'%'

this should return all strings starting with a\' but it returns
nothing!!!


\ is also the quoting character of LIKE, in addition to being a quoting
character on the string literal level. If you want all strings
starting with a\' then use something like:

a LIKE 'a\\\'%' ESCAPE '!'

where '!' selects some other escape character for LIKE that doesn't get
in the way. The documentation on LIKE contains the details on this
mechanism.
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #2
Tim Robinson wrote:
select * from temp where a like 'a\\\'%'

this should return all strings starting with a\' but it returns
nothing!!!


\ is also the quoting character of LIKE, in addition to being a quoting
character on the string literal level. If you want all strings
starting with a\' then use something like:

a LIKE 'a\\\'%' ESCAPE '!'

where '!' selects some other escape character for LIKE that doesn't get
in the way. The documentation on LIKE contains the details on this
mechanism.
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #3

-----Original Message-----
From: Peter Eisentraut [mailto:pe*****@gmx.net]
Sent: 20 June 2004 14:07
To: Tim Robinson; pg***********@postgresql.org
Subject: Re: [GENERAL] Help please - completely baffled by quoting
Tim Robinson wrote:
select * from temp where a like 'a\\\'%'

this should return all strings starting with a\' but it returns
nothing!!!


\ is also the quoting character of LIKE, in addition to being
a quoting
character on the string literal level. If you want all strings
starting with a\' then use something like:

a LIKE 'a\\\'%' ESCAPE '!'

where '!' selects some other escape character for LIKE that
doesn't get
in the way. The documentation on LIKE contains the details on this
mechanism.


or..
a LIKE 'a\\\\\'%'

thanks, I get it now :)

--- Tim
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #4

-----Original Message-----
From: Peter Eisentraut [mailto:pe*****@gmx.net]
Sent: 20 June 2004 14:07
To: Tim Robinson; pg***********@postgresql.org
Subject: Re: [GENERAL] Help please - completely baffled by quoting
Tim Robinson wrote:
select * from temp where a like 'a\\\'%'

this should return all strings starting with a\' but it returns
nothing!!!


\ is also the quoting character of LIKE, in addition to being
a quoting
character on the string literal level. If you want all strings
starting with a\' then use something like:

a LIKE 'a\\\'%' ESCAPE '!'

where '!' selects some other escape character for LIKE that
doesn't get
in the way. The documentation on LIKE contains the details on this
mechanism.


or..
a LIKE 'a\\\\\'%'

thanks, I get it now :)

--- Tim
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: | last post by:
OK: Purpose: Using user's input and 3 recursive functions, construct an hour glass figure. Main can only have user input, loops and function calls. Recursive function 1 takes input and displays...
11
by: milkyway | last post by:
Hello, I have an HTML page that I am trying to import 2 .js file (I created) into. These files are: row_functions.js and data_check_functions.js. Whenever I bring the contents of the files into...
2
by: Paul E Johnson | last post by:
Dear friends in C: I'm completely baffled by this problem I have with printf statements and conditional operators in C. I'm using gcc-3.3. I have a project where the rarely used Union type...
2
by: Trint Smith | last post by:
Ok, My program has been formating .txt files for input into sql server and ran into a problem...the .txt is an export from an accounting package and is only supposed to contain comas (,) between...
0
by: Tim Robinson | last post by:
Hi, I generally consider myself competent with the complexities of quoting but I can't figure out postgres at all. I've read the manual and it looks very straightforward but that doesn't accord...
1
by: Philipp Lenz | last post by:
I'm completely new to ASP.Net 2.0 and I'm baffled about what to do to get this to work. FYI, I'm not new at this, I've used asp.net 1.1 for allmost 4 years now. I'm running a development...
5
by: anthony | last post by:
I am trying to use get http: to access a web site and parse the html returned. I open a socket and send a request across of the form GET address http/1.0 where address is the specifics i am...
5
by: Nmx | last post by:
Hi everyone, I'm writing a patch to a search engine (aspseek http://www.aspseek.org/) compile under gcc 3.4.4 on FC3. At some point, I found this piece of code: -- // Dirty hack to avoid...
14
by: EJ | last post by:
I'm real new to javasscript. The task is to develop a web page which will allow users to customize a laptop ... show the price as they change options ... transfer the price and system description...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.