<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum PostgreSQL - Tworzenie nowej tabeli przez funkcję]]></title>
	<link rel="self" href="http://forum.postgresql.org.pl/extern.php?action=feed&amp;tid=399&amp;type=atom"/>
	<updated>2010-02-13T16:05:28Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.postgresql.org.pl/viewtopic.php?id=399</id>
		<entry>
			<title type="html"><![CDATA[Odp: Tworzenie nowej tabeli przez funkcję]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1840#p1840"/>
			<content type="html"><![CDATA[Problem rozwiązany - pomogła zmiana typu zmiennych z text na char(n).]]></content>
			<author>
				<name><![CDATA[MM]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1066</uri>
			</author>
			<updated>2010-02-13T16:05:28Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1840#p1840</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Tworzenie nowej tabeli przez funkcję]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1839#p1839"/>
			<content type="html"><![CDATA[Dodaję dane:

[code]
INSERT INTO test (nazwa, czas) VALUES ('a', 'b');
[/code]

i ukazuje się taki błąd
[code]
Error code 0, SQL state 42601: ERROR: syntax error at or near "b"
[/code]


Trigger mam zadeklarowny w ten sposób:
[code]
CREATE TRIGGER trg AFTER INSERT ON test EXECUTE PROCEDURE temp();
[/code]]]></content>
			<author>
				<name><![CDATA[MM]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1066</uri>
			</author>
			<updated>2010-02-13T12:17:33Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1839#p1839</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Tworzenie nowej tabeli przez funkcję]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1838#p1838"/>
			<content type="html"><![CDATA[No to jeszcze zacytuj błąd jaki występuje.]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2010-02-13T11:10:00Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1838#p1838</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Tworzenie nowej tabeli przez funkcję]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1837#p1837"/>
			<content type="html"><![CDATA[Faktycznie wkradł się mały błąd. Poprawione już.]]></content>
			<author>
				<name><![CDATA[MM]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1066</uri>
			</author>
			<updated>2010-02-13T10:46:24Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1837#p1837</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Tworzenie nowej tabeli przez funkcję]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1836#p1836"/>
			<content type="html"><![CDATA[[quote]
 a := test || nazwa_serwisu;
[/quote]
a co to niby ma robić, bo jeśli dobrze wiedzę to 'test' to nazwa tabeli tak?]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2010-02-13T10:20:48Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1836#p1836</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Tworzenie nowej tabeli przez funkcję]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1834#p1834"/>
			<content type="html"><![CDATA[Witam

Zmagam się z następującym problemem:
Po dodaniu nowych wartości do tabeli [b]test[/b] funkcja [b]temp[/b] powinna utworzyć nową tabelę o nazwie zależnej od tych wprowadzonych wartości.
np. po dodaniu 
[code]
INSERT INTO test (nazwa, czas) VALUES ('a', 'b');
[/code]

powinna utworzyć się tabela o nazwie [b]Temperatura_ab[/b]

Niestety problem wystepuje przy próbie połączenia tych 2 wartości i przypisania ich do zmiennej a. 




[code]
CREATE TABLE test (ID serial, nazwa char(20), czas char(4));
[/code]

[code]
CREATE OR REPLACE FUNCTION temp ()
RETURNS trigger AS '

DECLARE

    nazwa_serwisu text;     
    typ text;
    a text;


BEGIN

    SELECT nazwa INTO nazwa_serwisu FROM test WHERE id=(SELECT COUNT (*) FROM test);
    SELECT czas INTO typ FROM test WHERE id=(SELECT COUNT (*) FROM test);
    
    a := nazwa_serwisu || typ;

    execute '' CREATE TABLE Temperatura_''|| a ||''(nazwa char(20)) WITH OIDS'';

RETURN NEW;
END;
'
LANGUAGE 'plpgsql';
[/code]]]></content>
			<author>
				<name><![CDATA[MM]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1066</uri>
			</author>
			<updated>2010-02-12T21:35:40Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1834#p1834</id>
		</entry>
</feed>
