<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum PostgreSQL - relkind - pobranie nazwy tabeli + sequence]]></title>
	<link rel="self" href="http://forum.postgresql.org.pl/extern.php?action=feed&amp;tid=1354&amp;type=atom"/>
	<updated>2012-06-27T06:56:28Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.postgresql.org.pl/viewtopic.php?id=1354</id>
		<entry>
			<title type="html"><![CDATA[Odp: relkind - pobranie nazwy tabeli + sequence]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=3651#p3651"/>
			<content type="html"><![CDATA[Jest to wykorzystanie w funkcji substring wyrażeń regularnych choć w dość specyficzny sposób. O wyrażeniach regularnych poczytaj w wikipedii jest to tam dość dokładnie opisane. Ogólnie mówiąc funkcja substring działa trochę podobnie do like tyle ze wycina ciąg, który znajduje się pomiędzy znakiem po kwalifikatorze FOR i znakiem cudzysłow (") dodatkowo ciag musi spełniać warunki opisane we wzorcu po kwalifikatorze FROM. Trochę to zawile wiec może mały przykład.
[b]Przykład 1:[/b]
 Załóżmy ze chcesz z ciągu 123456 wyciąć podciąg zaczynając po znaku 2 i kończąc przed znakiem 5 to robisz to tak 
select substring ('123456' from '%2*"%*"5%' for '*')  
Znaki [b]% _[/b] jak w like. W tym przypadku kombinacja znaków *" oznacza miejsce wycięcia
[b]Przykład 2:[/b]
warunki jak dla przykładu 1 ale dodatkowo chcesz by podciąg spełniał warunek podciąg ma być 2 znakowy i kończyć się czwórka 
select substring ('123456' from '%2*"_4*"5%' for '*')]]></content>
			<author>
				<name><![CDATA[c_michal]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=627</uri>
			</author>
			<updated>2012-06-27T06:56:28Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=3651#p3651</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: relkind - pobranie nazwy tabeli + sequence]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=3650#p3650"/>
			<content type="html"><![CDATA[Witam
Może to śmieszne pytanie, ale czy może mi ktoś podpowiedzieć gdzie znajdę rozszyfrowanie tego
atr.adsrc from '%nextval_''#"%#"''%' for '#'

Nie jest mi to potrzebne, ale chciałbym wiedzieć o co chodzi w tej "chińszczyźnie"

Z góry dzięki za odpowiedź
AdamP.]]></content>
			<author>
				<name><![CDATA[adamleon]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=873</uri>
			</author>
			<updated>2012-06-27T06:10:30Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=3650#p3650</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: relkind - pobranie nazwy tabeli + sequence]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=3648#p3648"/>
			<content type="html"><![CDATA[u mnie działa to tak jak w poniższym zapytaniu - jeśli nie ci działała funkcja currval użyj nextval
select n.nspname as schema_name,c.relname as table_name
         ,col.attname as column_name
         ,substring(atr.adsrc from '%nextval_''#"%#"''%' for '#') as seq_name
         ,case when length(substring(atr.adsrc from '%nextval_''#"%#"''%' for '#'))!=0 then currval(substring(atr.adsrc from '%nextval_''#"%#"''%' for '#')) else null end as seq_value 
from pg_class c
join pg_attribute col on c.oid=col.attrelid and col.atttypid != 0::oid
left join pg_namespace n ON n.oid = c.relnamespace
left join pg_attrdef atr on c.oid=atr.adrelid and col.attnum=atr.adnum
where col.attnum>0 and relkind in('r') and c.oid not in (select relid from pg_statio_sys_tables)
order by n.nspname,c.relname,col.attnum]]></content>
			<author>
				<name><![CDATA[c_michal]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=627</uri>
			</author>
			<updated>2012-06-26T06:15:58Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=3648#p3648</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: relkind - pobranie nazwy tabeli + sequence]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=3647#p3647"/>
			<content type="html"><![CDATA[ja potrzebuję tą wartość przy listowaniu tabel.]]></content>
			<author>
				<name><![CDATA[przesq]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1211</uri>
			</author>
			<updated>2012-06-21T06:33:51Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=3647#p3647</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: relkind - pobranie nazwy tabeli + sequence]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=3646#p3646"/>
			<content type="html"><![CDATA[do sprawdzenia bieżącą wartość sekwencji użyj funcji currval(regclass)
dokumentacja znajduje się pod adresem [url]http://www.postgresql.org/docs/8.1/static/functions-sequence.html[/url]]]></content>
			<author>
				<name><![CDATA[c_michal]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=627</uri>
			</author>
			<updated>2012-06-20T11:44:05Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=3646#p3646</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: relkind - pobranie nazwy tabeli + sequence]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=3645#p3645"/>
			<content type="html"><![CDATA[Tak działa (przed column_name brakowało as).
Nie potrzebnie pobierało kolumny i ograniczyłem to do jednego schematu:

[code]
select n.nspname as schema_name,c.relname as table_name

         ,substring(atr.adsrc from '%nextval_''#"%#"''%' for '#') as seq_name
from pg_class c

left join pg_namespace n ON n.oid = c.relnamespace
left join pg_attrdef atr on c.oid=atr.adrelid 
where n.nspname='mg' and relkind in('r') and c.oid not in (select relid from pg_statio_sys_tables)
order by n.nspname, c.relname
[/code]

Potrzebuję jeszcze pobrać bieżącą wartość sekwencji dla każdej tabeli w tym samym zapytaniu - szukałem w tabelach pg ale nie znalazłem.]]></content>
			<author>
				<name><![CDATA[przesq]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1211</uri>
			</author>
			<updated>2012-06-20T07:39:23Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=3645#p3645</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: relkind - pobranie nazwy tabeli + sequence]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=3644#p3644"/>
			<content type="html"><![CDATA[to chyba powinno być tak - działa na wersji 9 postgresql

select n.nspname as schema_name,c.relname as table_name
         ,col.attname column_name
         ,substring(atr.adsrc from '%nextval_''#"%#"''%' for '#') as seq_name
from pg_class c
join pg_attribute col on c.oid=col.attrelid and col.atttypid != 0::oid
left join pg_namespace n ON n.oid = c.relnamespace
left join pg_attrdef atr on c.oid=atr.adrelid and col.attnum=atr.adnum
where col.attnum>0 and relkind in('r') and c.oid not in (select relid from pg_statio_sys_tables)
order by n.nspname,c.relname,col.attnum]]></content>
			<author>
				<name><![CDATA[c_michal]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=627</uri>
			</author>
			<updated>2012-06-19T22:33:14Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=3644#p3644</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[relkind - pobranie nazwy tabeli + sequence]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=3643#p3643"/>
			<content type="html"><![CDATA[Witam,

Mam zapytanie listujące tabele w bazie :
[code]
Select relname as tablename from pg_class where relkind in ('r') and relname not like 'pg_%' and relname not like 'sql_%' order by tablename;
[/code]

Jak zrobić aby pobrało mi jednocześnie nazwę sequence dla danej tabeli? W manualu jest, że wystarczy zmienić 'r' na 'S' ale nie wychodzi mi to w jednym zapytaniu.
Będę jeszcze potrzebował wartość nextval('tabela_id_seq').]]></content>
			<author>
				<name><![CDATA[przesq]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1211</uri>
			</author>
			<updated>2012-06-19T12:36:39Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=3643#p3643</id>
		</entry>
</feed>
