Thread: regarding contains operator

regarding contains operator

From
"surabhi.ahuja"
Date:
 i have a field whose type is varchar(16)
 
and the field is multivalued, in the sense it is of the form
 
abc\def\tez
(i.e. backslash separed values)
 
please tell me is there any operator available which enables me to do the following:
 
field contains <some value>
 
eg field contains "abc" should return true, similary for def or tez
 
if it is not ther can i write my own operators? abd use them please send me the link where i can find documnetation on the same
thanks,
regards
Surabhi Ahuja
 

Re: regarding contains operator

From
Ragnar
Date:
On mið, 2006-03-08 at 15:13 +0530, surabhi.ahuja wrote:
>
> if it is not ther can i write my own operators? abd use them please
> send me the link where i can find documnetation on the same

http://www.postgresql.org/docs/8.1/interactive/extend.html
http://www.postgresql.org/docs/8.1/interactive/xoper.html

gnari



Re: regarding contains operator

From
Michael Fuhr
Date:
On Wed, Mar 08, 2006 at 03:13:40PM +0530, surabhi.ahuja wrote:
> please tell me is there any operator available which enables me to do the following:
>
> field contains <some value>
>
> eg field contains "abc" should return true, similary for def or tez

See "Pattern Matching" in the "Functions and Operators" chapter of
the documentation.

http://www.postgresql.org/docs/8.1/interactive/functions-matching.html

You mentioned that your data contains backslashes.  Backslashes
have special meaning to the string parser and in search patterns,
so if you need to match a literal backslash then you might need to
write more backslashes than you'd expect.  If you're using 8.0 or
later then dollar quotes can make writing patterns easier because
they don't treat backslashes as special.

http://www.postgresql.org/docs/8.1/interactive/sql-syntax.html#SQL-SYNTAX-DOLLAR-QUOTING

--
Michael Fuhr

Re: regarding contains operator

From
Tom Lane
Date:
"surabhi.ahuja" <surabhi.ahuja@iiitb.ac.in> writes:
>  i have a field whose type is varchar(16)
> and the field is multivalued, in the sense it is of the form

> abc\def\tez
> (i.e. backslash separed values)

To be blunt, this is a really poorly-chosen data representation.
To point out just one problem, backslashes in the values will cause
you headaches.

Perhaps an array field would serve you better.  Then the specific
operation you are considering would be "foo = ANY(arrayfield)".

            regards, tom lane