Dollar quoting inside a regex bracket expression

From: David Fetter <david(at)fetter(dot)org>
To: PostgreSQL Bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Dollar quoting inside a regex bracket expression
Date: 2004-09-27 02:29:45
Message-ID: 20040927022945.GA24896@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Kind people,

I was checking edge cases with dollar quoting, and ran across
something I don't quite understand. This is in CVS TIP as of this
afternoon. The two functions below are different only in that inside
the regex bracket expression, the first uses \\ to indicate a literal
\, while the second attempts to use $qq$\$qq$ for the same thing. Is
this a bug? A feature that needs documenting? Some obvious thing
I've missed?

TIA for help on this.

------------------------------
-- --
-- This does as expected: --
-- --
------------------------------

test=# CREATE OR REPLACE FUNCTION has_bad_chars(text) RETURNS BOOLEAN
AS $function$
test$# SELECT $1 ~ $q$[\t\r\n\v|\\]$q$;
test$# $function$ LANGUAGE SQL;
CREATE FUNCTION
test=# select has_bad_chars($$\t$$);
has_bad_chars
---------------
t
(1 row)

----------------------
-- --
-- This does not. --
-- --
----------------------
CREATE OR REPLACE FUNCTION has_bad_chars(text) RETURNS BOOLEAN
AS $function$
SELECT $1 ~ $q$[\t\r\n\v|$qq$\$qq$]$q$;
$function$ LANGUAGE SQL;
CREATE FUNCTION
SELECT has_bad_chars($$\t$$);
has_bad_chars
---------------
f
(1 row)

--
David Fetter david(at)fetter(dot)org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778

Remember to vote!

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2004-09-27 03:45:42 Re: Dollar quoting inside a regex bracket expression
Previous Message Stephan Szabo 2004-09-26 18:15:25 Re: BUG #1266: Improper unique constraint / MVCCactivitieswithin