I made a request to pgAdmin and came across this weird behavior.
I was connected to a server running PostgreSQL 9.1.9.
I have a table called messages with the following definition:
ghareh@godot:~$ psql psql (9.1.9) Type "help" for help. ghareh=# \d messages Table "public.messages" Column | Type | Modifiers ---------------+-----------------------------+--------------------------------- messageid | character varying(200) | not null senderaliasid | integer | not null referenceid | character varying(200) | default NULL::character varying recipaliasid | integer | datetime | timestamp(2) with time zone | not null subject | character varying(512) | not null body | text | not null listid | integer | Indexes: "messages_pkey" PRIMARY KEY, btree (messageid) "messages_datetime_idx" btree (datetime) "recipaliasid_idx" btree (recipaliasid) "referenceid_idx" btree (referenceid) "senderaliasid_idx" btree (senderaliasid) Foreign-key constraints: "messages_listid_fkey" FOREIGN KEY (listid) REFERENCES lists(listid) "messages_recip_fkey" FOREIGN KEY (recipaliasid, listid) REFERENCES aliases(aliasid, listid) "messages_sender_fkey" FOREIGN KEY (senderaliasid, listid) REFERENCES aliases(aliasid, listid) Referenced by: TABLE "messages_attachments" CONSTRAINT "pkfkmid" FOREIGN KEY (messageid) REFERENCES messages(messageid)
My question includes body and subject columns.
I had a query that generated a result set. Then, to clarify my query, I added the term: where body like '%JSON%' ie, a subset of the results in which the body contains the string "JSON".
I got some results containing the word, and some not! But if I were looking for an arbitrary string, the results would be fine. I checked and found out that the query consists not only in finding the body column, but also in the topic column, which is crazy.
Here is my initial request:
select * from messages where messageid = '44BC310F.1090305@torrez.us'
which returns 1 row:
messageid: "44BC310F.1090305@torrez.us"; senderaliasid: 13777; referenceid: "7edfeeef0607171746r7d708067g15c77c3aa0ef9158@mail.gmail.com"; recipaliasid: ; datetime: "2006-07-17 20:53:35-07"; listid: 251; subject: "Re: svn commit: r422930 - /incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/json/JSONWriter.java"; body: "busted! thanks for the thorough review. -Elias Garrett Rooney wrote: > On 7/17/06, eliast@apache.org <eliast@apache.org> wrote: >> Author: eliast >> Date: Mon Jul 17 17:44:10 2006 >> New Revision: 422930 >> >> URL: http://svn.apache.org/viewvc?rev=422930 (...)"
If I am looking for:
select * from messages where messageid = '44BC310F.1090305@torrez.us' and body like '%JSON%'
I should not get any results, because there is not one in the body. But I still get the same line - it would seem because "JSON" is in subject ?
I even tried this:
select * from messages where messageid = '44BC310F.1090305@torrez.us' and body like '%incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/json/JSONWriter.java%'
and I still got the same row back. I am very confused.
I tried to reproduce the results on sqlfiddle.com but I failed. There I get what is expected from the sql select query:
http://sqlfiddle.com/#!1/ec74c/4