<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum PostgreSQL - Prosty kalkulator]]></title>
	<link rel="self" href="http://forum.postgresql.org.pl/extern.php?action=feed&amp;tid=1498&amp;type=atom"/>
	<updated>2013-05-20T12:34:58Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.postgresql.org.pl/viewtopic.php?id=1498</id>
		<entry>
			<title type="html"><![CDATA[Odp: Prosty kalkulator]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=4200#p4200"/>
			<content type="html"><![CDATA[nadal to bardzo dziwne ale OK. Poniżej masz kod

CREATE FUNCTION test3(IN zm1 integer, IN zm2 integer, IN zm3 varchar) RETURNS double precision AS
$BODY$
select case zm3 when '+' then (zm1+zm2)::double precision
                when '-' then (zm1-zm2)::double precision 
                when '*' then (zm1*zm2)::double precision 
                when '/' then (zm1/zm2)::double precision 
                else null::double precision 
                end;
$BODY$
LANGUAGE sql 
IMMUTABLE
RETURNS NULL ON NULL INPUT;

Sposób użycia:
select test3(1,2,'+')
union all select test3(1,2,'-')
union all select test3(1,2,'*')
union all select test3(1,2,'/')
union all select test3(1,2,'k')
union all select test3(null,2,'+');]]></content>
			<author>
				<name><![CDATA[c_michal]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=627</uri>
			</author>
			<updated>2013-05-20T12:34:58Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=4200#p4200</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Prosty kalkulator]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=4197#p4197"/>
			<content type="html"><![CDATA[Chodzi mi o utworzenie formuły bazując na where i elsif , abym mógł później wstawić zmienne z SELECT i to będzie działało. Używam postgreSQL 9.]]></content>
			<author>
				<name><![CDATA[Tiku]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1578</uri>
			</author>
			<updated>2013-05-20T08:46:26Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=4197#p4197</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Prosty kalkulator]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=4187#p4187"/>
			<content type="html"><![CDATA[Dziwne pytanie - prostymi działaniami arytmetycznymi nie ma co obciążać serwer powinieneś to działanie wykonać po stronie klienta, który korzysta z bazy danych. Wydaje się że jeżeli już masz to zrobić na poziomie bazy danych to masz wszystkie dane by zbudować prosty select który zwróci Ci wynik np.

Select 7*6; 
select 2+8;
select 5-8;
itd.
Jeśli ta odpowiedź Ci nie wystarcza napisz dlaczego potrzebujesz wykonać te działania w funkcji. (napisz też którą wersją bazy danych się posługujesz)]]></content>
			<author>
				<name><![CDATA[c_michal]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=627</uri>
			</author>
			<updated>2013-05-19T21:13:42Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=4187#p4187</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Prosty kalkulator]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=4185#p4185"/>
			<content type="html"><![CDATA[Mam takie oto zadanko : Napisz funkcję kalkulator, która przyjmuje 3 parametry, 2 liczby i znak (np. '+')
realizującą 4 podstawowe działania arytmetyczne.

create or replace function test3 (zm1 int, zm2 int, zm3 varchar 80)
returns int as $$
declare
begin
if

i co dalej?

Z góry dziękuje za oferowaną pomoc.]]></content>
			<author>
				<name><![CDATA[Tiku]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1578</uri>
			</author>
			<updated>2013-05-19T19:04:41Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=4185#p4185</id>
		</entry>
</feed>
