<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum PostgreSQL - Funkcja contains dla tablic]]></title>
	<link rel="self" href="http://forum.postgresql.org.pl/extern.php?action=feed&amp;tid=271&amp;type=atom"/>
	<updated>2009-08-18T11:23:20Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.postgresql.org.pl/viewtopic.php?id=271</id>
		<entry>
			<title type="html"><![CDATA[Odp: Funkcja contains dla tablic]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1151#p1151"/>
			<content type="html"><![CDATA[Będziesz potrzebował własnej funkcji i może operatora. To moge zaproponowac na szybkiego (ale rozwiązanie nie jest perfekcyjne, nie podales co moga zawierac tablice, tu załozyłem ze nie moga zawierac znaku '*')
[code]
drop function contains(anyarray,anyarray) cascade;
create or replace function contains (a anyarray, b anyarray) returns boolean  as $$
declare
string varchar;
tab1 varchar;
tab2 varchar;
begin
select into tab1 array_to_string(m,' ') from (select array(select(a)[i]
        from generate_series(1,array_upper(a,1)) i order by 1) as m) foo2;

select into tab2 array_to_string(m,'*') from (select array(select(b)[i]
        from generate_series(1,array_upper(b,1)) i order by 1) as m) foo2;

select into string regexp_replace(tab1,tab2,'$');

if string like '%$%'
        then return true;
end if;
return false;
end;
$$
language plpgsql;

create operator === (
        leftarg = anyarray,
        rightarg = anyarray,
        commutator = ===,
        procedure = contains);
[/code]
i sposob uzycia 
[code]
postgres=# select 1 as result where array[1,2,3,4] === array[1,3,2];
 result 
--------
      1
(1 row)

postgres=# select 1 as result where array[1,2,3,4] === array[1,3,5];
 result 
--------
(0 rows)
[/code]

Mam nadzieje ze sie nigdzie nie walnąłem :).]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2009-08-18T11:23:20Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1151#p1151</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Funkcja contains dla tablic]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1150#p1150"/>
			<content type="html"><![CDATA[Potrzbuje wrzucic do zapytania operator zawierania jednej tablicy w drugiej. W nowych wersjach (od 8.2) Pgsql jest to operator "@>" ale ja musze to zrobić na wersji 8.1 (taki hosting :( ). Wiem może ktoś jak to zrobić ??]]></content>
			<author>
				<name><![CDATA[wojtek]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=961</uri>
			</author>
			<updated>2009-08-18T07:04:10Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1150#p1150</id>
		</entry>
</feed>
