I am trying to concatenate a variable using the LIKE statement and for some reason it only finds values where the word to search is at the end of the text variable.
I am using PostgreSQL 8.4 and this is stored in a function (stored procedure)
considering in this example:
a.key1 is "HELLO"
a_text is "I SAY HELLO TO THE WORLD"
Code:
SELECT count(1), a.key1, a.active, a.campkeydbid
FROM campkeydb a
WHERE a_text LIKE '%'|| a.key1 ||'%'
GROUP BY a.key1, a.active, a.campkeydbid
INTO a_count, a_campaignkey, a_active, a_campkeydbid;
In this stored procedure it will NOT return the values; it will not find the word "HELLO"?
It will ONLY return the values if a_text contains "I SAY HELLO"
Does anyone knows what I am doing wrong? It seems that it is correct as I am concatenating a % on both sides of the variable a.key1.
a.key1is exactly'HELLO'rather than' HELLO'or something similar? Try a quickselect '-' || key1 || '-' from campkeydbto see if you have stray spaces.a_textvalue? Have you tried running this query witha_textreplaced with the string itself?