Проблема с поиском в Postgres
Есть такой запрос :
Код:
SELECT DISTINCT e.exchange_id, bc.*, cr.*, e.*,
COUNT (DISTINCT im.eximage_id) as count_images,
date_trunc('second', e.exchange_editdate) AS exchange_editdate,
c.*, cl.*, e.place_id as place_id
FROM exchange e
INNER JOIN catalog c ON c.catalog_id=e.catalog_id
LEFT OUTER JOIN clients cl ON e.client_id=cl.client_id
LEFT OUTER JOIN currency cr ON cr.currency_id = e.currency_id
LEFT OUTER JOIN eximages im ON im.exchange_id = e.exchange_id
LEFT OUTER JOIN bclients bc ON e.bc_id = bc.bc_id
GROUP BY bc.bc_id, bc.bc_login, bc.bc_password, bc.bc_mail, bc.bc_contactface, bc.bc_post, bc.bc_firm, bc.place_id, bc.bc_placevector, bc.bc_regdate, bc.bc_session, bc.bc_submit, bc.bc_confirm, bc.bc_newssubscribe, bc.client_ident, bc.bc_contactface2, bc.bc_address, bc.bc_phone, bc.bc_fax, bc.bc_mobphone, bc.bc_open, bc.bc_openenddate, bc.bc_maxoffers, bc.bc_maxnotes, bc.bc_www, bc.bc_shortdesc, bc.bc_longdesc, e.exchange_id, e.bc_id, e.client_id, e.exchange_clientanother, e.exchange_date, e.exchange_visible, e.exchange_name, e.catalog_id, e.exchange_catalogvector, e.exchange_cataloganother, e.exchange_description, e.exchange_year, e.exchange_placevector, e.exchange_address, e.exchange_price, e.currency_id, e.exchange_days, e.exchange_enddate, e.place_id, e.exchange_pricecomment, e.exchange_editdate, e.exchange_catalogname, e.exchange_clientname, e.exchange_new, c.catalog_id,c.banner_id,c.catalog_banner_path,c.catalog_name,c.catalog_stripname,c.catalog_tagname,c.catalog_vector,c.catalog_level,c.catalog_parent_id,c.catalog_column,c.catalog_number,c.catalog_approve,c.client_id,c.image_id,c.catalog_htmlblock, c.theme_id, c.catalog_dir, cl.client_id,cl.client_ident,cl.client_login,cl.client_password,cl.client_contactface,cl.client_contactphone,cl.client_contactmail, cl.client_fullname,cl.client_shortname,cl.client_foundyear,cl.client_description,cl.client_info,cl.place_id,cl.client_factaddress, cl.client_uraddress,cl.client_rs,cl.client_ks,cl.client_bik,cl.client_bank,cl.client_inn,cl.client_postaddress,cl.client_mail,cl.client_www, cl.client_fax,cl.client_maxgoods,cl.client_allenter,cl.client_pay,cl.client_payenddate,cl.client_regdate,cl.client_gooddate,cl.client_clientdate, cl.client_lastlogindate,cl.logo1_id,cl.logo2_id,cl.client_id,cl.client_stripname,cl.client_session,cl.client_placevector,cl.client_countgoods,cl.client_keywords, cr.currency_id, cr.currency_name LIMIT 20 OFFSET 20
COUNT (DISTINCT im.eximage_id) as count_images,
date_trunc('second', e.exchange_editdate) AS exchange_editdate,
c.*, cl.*, e.place_id as place_id
FROM exchange e
INNER JOIN catalog c ON c.catalog_id=e.catalog_id
LEFT OUTER JOIN clients cl ON e.client_id=cl.client_id
LEFT OUTER JOIN currency cr ON cr.currency_id = e.currency_id
LEFT OUTER JOIN eximages im ON im.exchange_id = e.exchange_id
LEFT OUTER JOIN bclients bc ON e.bc_id = bc.bc_id
GROUP BY bc.bc_id, bc.bc_login, bc.bc_password, bc.bc_mail, bc.bc_contactface, bc.bc_post, bc.bc_firm, bc.place_id, bc.bc_placevector, bc.bc_regdate, bc.bc_session, bc.bc_submit, bc.bc_confirm, bc.bc_newssubscribe, bc.client_ident, bc.bc_contactface2, bc.bc_address, bc.bc_phone, bc.bc_fax, bc.bc_mobphone, bc.bc_open, bc.bc_openenddate, bc.bc_maxoffers, bc.bc_maxnotes, bc.bc_www, bc.bc_shortdesc, bc.bc_longdesc, e.exchange_id, e.bc_id, e.client_id, e.exchange_clientanother, e.exchange_date, e.exchange_visible, e.exchange_name, e.catalog_id, e.exchange_catalogvector, e.exchange_cataloganother, e.exchange_description, e.exchange_year, e.exchange_placevector, e.exchange_address, e.exchange_price, e.currency_id, e.exchange_days, e.exchange_enddate, e.place_id, e.exchange_pricecomment, e.exchange_editdate, e.exchange_catalogname, e.exchange_clientname, e.exchange_new, c.catalog_id,c.banner_id,c.catalog_banner_path,c.catalog_name,c.catalog_stripname,c.catalog_tagname,c.catalog_vector,c.catalog_level,c.catalog_parent_id,c.catalog_column,c.catalog_number,c.catalog_approve,c.client_id,c.image_id,c.catalog_htmlblock, c.theme_id, c.catalog_dir, cl.client_id,cl.client_ident,cl.client_login,cl.client_password,cl.client_contactface,cl.client_contactphone,cl.client_contactmail, cl.client_fullname,cl.client_shortname,cl.client_foundyear,cl.client_description,cl.client_info,cl.place_id,cl.client_factaddress, cl.client_uraddress,cl.client_rs,cl.client_ks,cl.client_bik,cl.client_bank,cl.client_inn,cl.client_postaddress,cl.client_mail,cl.client_www, cl.client_fax,cl.client_maxgoods,cl.client_allenter,cl.client_pay,cl.client_payenddate,cl.client_regdate,cl.client_gooddate,cl.client_clientdate, cl.client_lastlogindate,cl.logo1_id,cl.logo2_id,cl.client_id,cl.client_stripname,cl.client_session,cl.client_placevector,cl.client_countgoods,cl.client_keywords, cr.currency_id, cr.currency_name LIMIT 20 OFFSET 20
Он выполняется верно и все данные выводит. А если добавить к запросу условие такого типа :
Код:
SELECT DISTINCT e.exchange_id, bc.*, cr.*, e.*,
COUNT (DISTINCT im.eximage_id) as count_images,
date_trunc('second', e.exchange_editdate) AS exchange_editdate,
c.*, cl.*, e.place_id as place_id
FROM exchange e
INNER JOIN catalog c ON c.catalog_id=e.catalog_id
LEFT OUTER JOIN clients cl ON e.client_id=cl.client_id
LEFT OUTER JOIN currency cr ON cr.currency_id = e.currency_id
LEFT OUTER JOIN eximages im ON im.exchange_id = e.exchange_id
LEFT OUTER JOIN bclients bc ON e.bc_id = bc.bc_id
WHERE
e.exchange_name ~* '.*Fiat.*'
GROUP BY bc.bc_id, bc.bc_login, bc.bc_password, bc.bc_mail, bc.bc_contactface, bc.bc_post, bc.bc_firm, bc.place_id, bc.bc_placevector, bc.bc_regdate, bc.bc_session, bc.bc_submit, bc.bc_confirm, bc.bc_newssubscribe, bc.client_ident, bc.bc_contactface2, bc.bc_address, bc.bc_phone, bc.bc_fax, bc.bc_mobphone, bc.bc_open, bc.bc_openenddate, bc.bc_maxoffers, bc.bc_maxnotes, bc.bc_www, bc.bc_shortdesc, bc.bc_longdesc, e.exchange_id, e.bc_id, e.client_id, e.exchange_clientanother, e.exchange_date, e.exchange_visible, e.exchange_name, e.catalog_id, e.exchange_catalogvector, e.exchange_cataloganother, e.exchange_description, e.exchange_year, e.exchange_placevector, e.exchange_address, e.exchange_price, e.currency_id, e.exchange_days, e.exchange_enddate, e.place_id, e.exchange_pricecomment, e.exchange_editdate, e.exchange_catalogname, e.exchange_clientname, e.exchange_new, c.catalog_id,c.banner_id,c.catalog_banner_path,c.catalog_name,c.catalog_stripname,c.catalog_tagname,c.catalog_vector,c.catalog_level,c.catalog_parent_id,c.catalog_column,c.catalog_number,c.catalog_approve,c.client_id,c.image_id,c.catalog_htmlblock, c.theme_id, c.catalog_dir, cl.client_id,cl.client_ident,cl.client_login,cl.client_password,cl.client_contactface,cl.client_contactphone,cl.client_contactmail, cl.client_fullname,cl.client_shortname,cl.client_foundyear,cl.client_description,cl.client_info,cl.place_id,cl.client_factaddress, cl.client_uraddress,cl.client_rs,cl.client_ks,cl.client_bik,cl.client_bank,cl.client_inn,cl.client_postaddress,cl.client_mail,cl.client_www, cl.client_fax,cl.client_maxgoods,cl.client_allenter,cl.client_pay,cl.client_payenddate,cl.client_regdate,cl.client_gooddate,cl.client_clientdate, cl.client_lastlogindate,cl.logo1_id,cl.logo2_id,cl.client_id,cl.client_stripname,cl.client_session,cl.client_placevector,cl.client_countgoods,cl.client_keywords, cr.currency_id, cr.currency_name LIMIT 20 OFFSET 20
COUNT (DISTINCT im.eximage_id) as count_images,
date_trunc('second', e.exchange_editdate) AS exchange_editdate,
c.*, cl.*, e.place_id as place_id
FROM exchange e
INNER JOIN catalog c ON c.catalog_id=e.catalog_id
LEFT OUTER JOIN clients cl ON e.client_id=cl.client_id
LEFT OUTER JOIN currency cr ON cr.currency_id = e.currency_id
LEFT OUTER JOIN eximages im ON im.exchange_id = e.exchange_id
LEFT OUTER JOIN bclients bc ON e.bc_id = bc.bc_id
WHERE
e.exchange_name ~* '.*Fiat.*'
GROUP BY bc.bc_id, bc.bc_login, bc.bc_password, bc.bc_mail, bc.bc_contactface, bc.bc_post, bc.bc_firm, bc.place_id, bc.bc_placevector, bc.bc_regdate, bc.bc_session, bc.bc_submit, bc.bc_confirm, bc.bc_newssubscribe, bc.client_ident, bc.bc_contactface2, bc.bc_address, bc.bc_phone, bc.bc_fax, bc.bc_mobphone, bc.bc_open, bc.bc_openenddate, bc.bc_maxoffers, bc.bc_maxnotes, bc.bc_www, bc.bc_shortdesc, bc.bc_longdesc, e.exchange_id, e.bc_id, e.client_id, e.exchange_clientanother, e.exchange_date, e.exchange_visible, e.exchange_name, e.catalog_id, e.exchange_catalogvector, e.exchange_cataloganother, e.exchange_description, e.exchange_year, e.exchange_placevector, e.exchange_address, e.exchange_price, e.currency_id, e.exchange_days, e.exchange_enddate, e.place_id, e.exchange_pricecomment, e.exchange_editdate, e.exchange_catalogname, e.exchange_clientname, e.exchange_new, c.catalog_id,c.banner_id,c.catalog_banner_path,c.catalog_name,c.catalog_stripname,c.catalog_tagname,c.catalog_vector,c.catalog_level,c.catalog_parent_id,c.catalog_column,c.catalog_number,c.catalog_approve,c.client_id,c.image_id,c.catalog_htmlblock, c.theme_id, c.catalog_dir, cl.client_id,cl.client_ident,cl.client_login,cl.client_password,cl.client_contactface,cl.client_contactphone,cl.client_contactmail, cl.client_fullname,cl.client_shortname,cl.client_foundyear,cl.client_description,cl.client_info,cl.place_id,cl.client_factaddress, cl.client_uraddress,cl.client_rs,cl.client_ks,cl.client_bik,cl.client_bank,cl.client_inn,cl.client_postaddress,cl.client_mail,cl.client_www, cl.client_fax,cl.client_maxgoods,cl.client_allenter,cl.client_pay,cl.client_payenddate,cl.client_regdate,cl.client_gooddate,cl.client_clientdate, cl.client_lastlogindate,cl.logo1_id,cl.logo2_id,cl.client_id,cl.client_stripname,cl.client_session,cl.client_placevector,cl.client_countgoods,cl.client_keywords, cr.currency_id, cr.currency_name LIMIT 20 OFFSET 20
то результат нулевой, хотя записи в которых присутствует слово 'Fiat' существуют.
Столбец exchange_name - character varying(255)
БД: PostgreSQL 8.1.4
Кодировка базы: WIN1251
Подскажите, плз, что не так может быть?
Код:
SELECT DISTINCT e.* FROM exchange e WHERE e.exchange_name ~* '.*Fiat.*'