<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Forum PostgreSQL - function for search string in all table of a particular schema ? (post]]></title>
		<link>https://forum.postgresql.org.pl/viewtopic.php?id=1407</link>
		<description><![CDATA[Najświeższe odpowiedzi w function for search string in all table of a particular schema ? (post.]]></description>
		<lastBuildDate>Fri, 12 Oct 2012 23:50:58 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Odp: function for search string in all table of a particular schema ? (post]]></title>
			<link>https://forum.postgresql.org.pl/viewtopic.php?pid=3754#p3754</link>
			<description><![CDATA[Sorry bat my english is not good

this select generate script for all tables in schema public (postgreSql 9.1)

select string_agg('select count (*) ,'''||table_name||''' from '||table_name||' where ' ||where_text,' union all ') from
(
select table_schema||'.'||table_name as table_name ,string_agg(column_name || ' ilike ''%search_text%''',' or ') as where_text
from information_schema.columns where data_type in ('character','character varying','text') and table_schema ='public'
group by table_schema||'.'||table_name
) d]]></description>
			<author><![CDATA[dummy@example.com (c_michal)]]></author>
			<pubDate>Fri, 12 Oct 2012 23:50:58 +0000</pubDate>
			<guid>https://forum.postgresql.org.pl/viewtopic.php?pid=3754#p3754</guid>
		</item>
		<item>
			<title><![CDATA[function for search string in all table of a particular schema ? (post]]></title>
			<link>https://forum.postgresql.org.pl/viewtopic.php?pid=3752#p3752</link>
			<description><![CDATA[Hi ,

i want to create a function postgresql, that can able to search a string from all tables.
I try as below.... please rectify this 

CREATE OR REPLACE FUNCTION search_string(str char(50)) 
returnS character varying AS
$BODY$
DECLARE
tempCount bigint ;
record_v record;
itemid_v bigint ; 
query varchar; 
return_v character varying := null; 
BEGIN 
for record_v in (select table_name ,column_name 
from information_schema.columns and data_type in ('character','character varying','text')) loop
query := 'select count(*) from '|| record_v.table_name ||' where ' || record_v.column_name || ' like ''%' || str ||'%''' ;
execute query into tempcount;
if (tempCount >0) then
return 'l';
else
return '2572';
end if;
end loop;
END;
$BODY$ LANGUAGE plpgsql VOLATILE
COST 100;


in output i need all tables in which string exists :
like table_name count_of_string_match]]></description>
			<author><![CDATA[dummy@example.com (garry0001)]]></author>
			<pubDate>Thu, 11 Oct 2012 14:04:24 +0000</pubDate>
			<guid>https://forum.postgresql.org.pl/viewtopic.php?pid=3752#p3752</guid>
		</item>
	</channel>
</rss>
