regarding contains operator

Started by surabhi.ahujaabout 20 years ago4 messagesgeneral
Jump to latest
#1surabhi.ahuja
surabhi.ahuja@iiitb.ac.in

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

#2Ragnar
gnari@hive.is
In reply to: surabhi.ahuja (#1)
Re: regarding contains operator

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

#3Michael Fuhr
mike@fuhr.org
In reply to: surabhi.ahuja (#1)
Re: regarding contains operator

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

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: surabhi.ahuja (#1)
Re: regarding contains operator

"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