<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum PostgreSQL - PostgreSQL - funkcje - problem z dodawaniem zmiennych ;/]]></title>
	<link rel="self" href="http://forum.postgresql.org.pl/extern.php?action=feed&amp;tid=241&amp;type=atom"/>
	<updated>2009-06-19T08:35:45Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.postgresql.org.pl/viewtopic.php?id=241</id>
		<entry>
			<title type="html"><![CDATA[Odp: PostgreSQL - funkcje - problem z dodawaniem zmiennych ;/]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1037#p1037"/>
			<content type="html"><![CDATA[Huh ;) zadzialalo ;)

Chyba faktycznie te selecty cos nie tak strugaly ... 

dzieki za pomoc ;)]]></content>
			<author>
				<name><![CDATA[v0jt4s]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=933</uri>
			</author>
			<updated>2009-06-19T08:35:45Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1037#p1037</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: PostgreSQL - funkcje - problem z dodawaniem zmiennych ;/]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1033#p1033"/>
			<content type="html"><![CDATA[Odpowiedz moze byc bardzo prosta. Jesteś pewien, że w tabeli występuje wartość max(invoices_id)-1. max(invoices_id)-1 to wcale nie musi być wartośc występująca z tabeli. Ty chcesz drugą największą pod względem wartości liczbę z tabeli ale nie jest powiedziane, ze ta liczba to wlasnie max(invoices_id)-1
Bo jeśli nie występuje to z_invoce_nr z select'a będzie równe NULL
a operacja
[code]
z_invoice_nr := z_invoice_nr+1;
[/code]
też zwróci null bo null+1=null;
Może tak
[code]
select invoice_nr as z_invoice_nr from
(select * from jd_invoices_test where invoices_id < (select max(invoices_id) from jd_invoices_test)
) foo order by invoices_id desc limit 1;
[/code]

Mam nadzieje, ze nie ma zadnych bledów skladniowych bo nie ma postgresa pod reka.]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2009-06-18T16:59:46Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1033#p1033</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: PostgreSQL - funkcje - problem z dodawaniem zmiennych ;/]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1032#p1032"/>
			<content type="html"><![CDATA[ok, to fajne ... ;) dzieki za podpowiedz, 
tylko ze to nie bedzie tak dzialac :/
Twoje zapytanie wyciagnie min(invoice_id) a ja potrzebuje max(invoice_id)-1

[code]select invoice_nr as z_invoice_nr from jd_invoices_test where invoices_id in (select max(invoices_id)-1 from jd_invoices_test)[/code]

Ale nadal nie nie wiem dlaczego nie zwiekasz mi z_invoice_nr, dodam jeszcze ze w tablicy jd_invoices  kolumna invoice_nr ma typ integer a update nie robi nic albo wpisuje w invoice_nr wartos NULL ;/]]></content>
			<author>
				<name><![CDATA[v0jt4s]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=933</uri>
			</author>
			<updated>2009-06-18T16:45:25Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1032#p1032</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: PostgreSQL - funkcje - problem z dodawaniem zmiennych ;/]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1031#p1031"/>
			<content type="html"><![CDATA[[code]
   select invoices_id into z_invoices_id from jd_invoices_test order by invoices_id desc limit 1;
   select invoice_nr into z_invoice_nr from jd_invoices_test where invoices_id = z_invoices_id;
[/code]
a może lepiej tak
[code]
   select invoice_nr into z_invoice_nr from jd_invoices_test where invoices_id = select (min(invoices_id) from jd_invoices_test)
[/code]
Chyba robi to samo.]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2009-06-18T16:41:26Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1031#p1031</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[PostgreSQL - funkcje - problem z dodawaniem zmiennych ;/]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1025#p1025"/>
			<content type="html"><![CDATA[Witam.

  Ponizej wkleilem funkcje jaka jest wywolywana przez TRIGGER (AFTER INSERT ON) problem polega na tym, że jak probuje podstawic pod zmienna 'z_invoice_nr' := z_invoice_nr+1 to nie wstawia nic w UPDATE, natomiast jezeli przypisze na sztywno dowolna cyfre wszystko dziala.
Moze ma ktos pomysl co jest zle zapisane ?

[code]
declare
  z_invoice_nr                           numeric(6,0);
  z_invoices_id                           integer;
begin

   select invoices_id into z_invoices_id from jd_invoices_test order by invoices_id desc limit 1;
   select invoice_nr into z_invoice_nr from jd_invoices_test where invoices_id = z_invoices_id;

   z_invoice_nr := z_invoice_nr+1;
   
   update jd_invoices_test set invoice_nr = z_invoice_nr where invoices_id = new.invoices_id; 

    return new;
end;
[/code]

I jeszcze jedno zauwazyliscie pewnie ze wyciagam wczeniejszy rekord takim troche dziwnym selectem 

[code]select invoices_id into z_invoices_id from jd_invoices_test order by invoices_id desc limit 1;[/code]
 jest moze jakis inny sposob aby wyciagnac wczesniejszy rekord?

pozdrawiam
W.]]></content>
			<author>
				<name><![CDATA[v0jt4s]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=933</uri>
			</author>
			<updated>2009-06-18T14:30:21Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1025#p1025</id>
		</entry>
</feed>
