Re: BUG #5126: convert_to preventing index scan - Mailing list pgsql-bugs

From Andrew Gierth
Subject Re: BUG #5126: convert_to preventing index scan
Date
Msg-id 87zl7jlu0f.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to Re: BUG #5126: convert_to preventing index scan  (Peter Eisentraut <peter_e@gmx.net>)
Responses Re: BUG #5126: convert_to preventing index scan
List pgsql-bugs
>>>>> "Peter" == Peter Eisentraut <peter_e@gmx.net> writes:

 >> I have table with bytea column, which is indexed (1)
 >> I want to use index during pattern matching (eg. dir like
 >> someDirectoryName
 >> || '/%'), but concatenation of two strings cause error (2)
 >> So I have to use function convert_to (converting text to bytea), but
 >> this
 >> has awful explain plan (3)

 Peter> You haven't told us how the convert_to function is defined.

convert_to is a builtin function. If there's a bug here, it's that
convert_to is defined as stable rather than immutable. (Sure it depends
on server_encoding, but that can't exactly change... if there's any
other reason why it's not immutable, I can't think what it is.)

Example (5) from the original message is the correct approach in any
case; as long as either operand of the || is explicitly passed as, or
cast to, a bytea, then it should work.

--
Andrew (irc:RhodiumToad)

pgsql-bugs by date:

Previous
From: "aihongwei"
Date:
Subject: BUG #5131: The pgsql will lost
Next
From: Robert Haas
Date:
Subject: Re: BUG #5131: The pgsql will lost