Re: [HACKERS] Using backslash in query

2003-10-04 Thread Hannu Krosing
Tom Lane kirjutas R, 03.10.2003 kell 18:34:
 Michael Brusser [EMAIL PROTECTED] writes:
  But when I doubled the number of backslashes:
SELECT smth. FROM  tbl WHERE situation LIKE '%%';
  - it actually worked fine.
 
 Backslash is special to both the string-literal parser and the LIKE code.
 So when you write the above, the pattern value that arrives at the LIKE
 processor has one less level of backslashing:
   %\\%
 and the LIKE processor interprets this as percent, a literal backslash,
 and another percent.

Regarding the dollar-quoting discussions -

Will we be able to write the above query as 

SELECT smth. FROM  tbl WHERE WHERE situation LIKE $$%\\%$$;

in 7.4 or is \ still special there ?

if it is then one \ in regex in plpython still needs to be entered as
 which has some geek coolness but would not be what I'd prefer
to do on a regular basis.


Hannu


---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [HACKERS] Using backslash in query

2003-10-04 Thread Andrew Dunstan

- Original Message - 
From: Hannu Krosing [EMAIL PROTECTED]

 Regarding the dollar-quoting discussions -

 Will we be able to write the above query as

 SELECT smth. FROM  tbl WHERE WHERE situation LIKE $$%\\%$$;


Yes, as I understand it (as long as you remove the one of the WHEREs :-) ).
If not we need some rethinking.  Think of this as our equivalent of XML's
CDATA quoting - you don't need to escape  or  or  inside a CDATA node.


 in 7.4 or is \ still special there ?

I don't believe so.


cheers

andrew


---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [HACKERS] Using backslash in query

2003-10-04 Thread Andrew Dunstan
but this will be in 7.5, not 7.4, won't it?

Andrew Dunstan wrote:

- Original Message - 
From: Hannu Krosing [EMAIL PROTECTED]
 

Regarding the dollar-quoting discussions -

Will we be able to write the above query as

SELECT smth. FROM  tbl WHERE WHERE situation LIKE $$%\\%$$;

   

Yes, as I understand it (as long as you remove the one of the WHEREs :-) ).
If not we need some rethinking.  Think of this as our equivalent of XML's
CDATA quoting - you don't need to escape  or  or  inside a CDATA node.
 

in 7.4 or is \ still special there ?
   

I don't believe so.

 



---(end of broadcast)---
TIP 6: Have you searched our list archives?
  http://archives.postgresql.org


Re: [HACKERS] Using backslash in query

2003-10-04 Thread Tom Lane
Hannu Krosing [EMAIL PROTECTED] writes:
 Regarding the dollar-quoting discussions -

 Will we be able to write the above query as 
 SELECT smth. FROM  tbl WHERE WHERE situation LIKE $$%\\%$$;
 in 7.4 or is \ still special there ?

We were discussing that for 7.5 not 7.4.  But yeah, it would work that
way because \ won't be treated specially in dollar-quoted literals.

regards, tom lane

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


[HACKERS] Using backslash in query

2003-10-03 Thread Michael Brusser
I'm afraid I'm confused about something very simple... but anyway

I need to run a query on a varchar field containing a backslash.
My first attempt looked like this:
  SELECT smth. FROM  tbl WHERE situation LIKE '%\\%';
This did not returned any rows.

I looked up for a reference, confirmed that
... double-backslash is required to represent a literal backslash.
http://www.postgresql.org/docs/aw_pgsql_book/node139.html#copy_backslash_han
dling

But when I doubled the number of backslashes:
  SELECT smth. FROM  tbl WHERE situation LIKE '%%';
- it actually worked fine.

Same thing happens with using regex: situation ~ '\\';

Could someone shed some light on this, please.

Mike.




---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [HACKERS] Using backslash in query

2003-10-03 Thread Tom Lane
Michael Brusser [EMAIL PROTECTED] writes:
 But when I doubled the number of backslashes:
   SELECT smth. FROM  tbl WHERE situation LIKE '%%';
 - it actually worked fine.

Backslash is special to both the string-literal parser and the LIKE code.
So when you write the above, the pattern value that arrives at the LIKE
processor has one less level of backslashing:
%\\%
and the LIKE processor interprets this as percent, a literal backslash,
and another percent.

regards, tom lane

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])