Received: from bologna.nettuno.it (bologna.nettuno.it [193.43.2.1]) by hub.org (8.9.3/8.9.3) with ESMTP id JAA59460 for ; Tue, 31 Aug 1999 09:52:08 -0400 (EDT) (envelope-from jose@sferacarta.com) Received: from proxy.sferacarta.com (mail@sfcabop1.nettuno.it [193.207.10.213]) by bologna.nettuno.it (8.9.3/8.9.3/NETTuno 3.3) with ESMTP id PAA16683; Tue, 31 Aug 1999 15:51:56 +0200 (MDT) Received: from rosso.sferacarta.com (sferacarta.com) [10.20.30.5] by proxy.sferacarta.com with esmtp (Exim 2.05 #1 (Debian)) id 11LojY-00044L-00; Tue, 31 Aug 1999 14:18:00 +0000 Message-ID: <37CBC957.AA46EC36@sferacarta.com> Date: Tue, 31 Aug 1999 14:23:51 +0200 From: =?iso-8859-1?Q?Jos=E9?= Soares X-Mailer: Mozilla 4.5 [it] (Win95; I) X-Accept-Language: it MIME-Version: 1.0 To: holm@freibergnet.de CC: Tom Lane , pgsql-sql@postgresql.org Subject: Re: [SQL] problem with select References: <19990830140452.B21897@pegasus.freibergnet.de> <5585.936024234@sss.pgh.pa.us> <19990831082920.A23046@pegasus.freibergnet.de> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Holm Tiffe ha scritto: > Tom Lane wrote: > > > Holm Tiffe writes: > > > What I try to find is a solution for a search in this table like this: > > > > > select distinct code,category from products where code ~* 'abc' or > > > category ~* 'abc' or manufacturer ~* 'abc' or description ~* 'abc' > > > or comment ~* 'abc' order by code; > > > > > So far so good, but I have the problem that I have the value 'abc' > > > only one times ! > > > > How about > > > > select distinct code,category from products where > > (code || category || manufacturer || ...) ~* 'abc'; > > > > Actually you'd probably want to also concatenate some separator markers, > > maybe (code || '|' || category || ...), so that you didn't get bogus > > matches across fields, like where code ends in 'a' and category starts > > with 'bc'. > > > > Note that this select will be a bit of a memory hog because > > text-slinging is very wasteful of space in 6.5 (the intermediate results > > from the concatenate operators don't get freed till end of transaction). > > So it might not be workable if you have a large database. I hope to see > > that fixed for 6.6 or 6.7. > > > > regards, tom lane > > Hm, clever. > > It is almost working, my database isn't that big that memory becomes a > problem; the machine has 512MB. > > But why is nothing found if one value of a column contains NULL ? > > select distinct code,category from products where (code || '|' || category > || '|' || comment || '|' || description || '|' || desc_de) ~* 'kde'; > code|category > ------+-------- > 06-001|KDE > (1 row) > > shop=> update products set comment = Null where code ='06-001'; > UPDATE 1 > shop=> select (comment || '|' || code) from products where code ~* '06-001'; > ?column? > -------- > > Try using the COALESCE function: select distinct code,category from products where (code || '|' || coalesce(category,' ') || '|' || coalesce(comment,' ') || '|' || coalesce(description,' ') || '|' || coalesce(desc_de,' ')) ~* 'kde'; José