<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum PostgreSQL - SELECT CASE UPDATE/INSERT]]></title>
	<link rel="self" href="http://forum.postgresql.org.pl/extern.php?action=feed&amp;tid=511&amp;type=atom"/>
	<updated>2010-12-07T20:04:25Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.postgresql.org.pl/viewtopic.php?id=511</id>
		<entry>
			<title type="html"><![CDATA[Odp: SELECT CASE UPDATE/INSERT]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2303#p2303"/>
			<content type="html"><![CDATA[dzięki]]></content>
			<author>
				<name><![CDATA[Rogo]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1161</uri>
			</author>
			<updated>2010-12-07T20:04:25Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2303#p2303</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: SELECT CASE UPDATE/INSERT]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2302#p2302"/>
			<content type="html"><![CDATA[No to bez funkcji się nie da ale .. wystarczy sobie utworzyć taką uniwersalną funkcję
[code]
create function execute(text) returns void as 
$$
begin 
execute $1;
end;
$$ 
language plpgsql; 
[/code]
i uzyć jej w tym case
[code]
SELECT CASE
   WHEN (SELECT id FROM .........) IS NULL THEN
      execute('INSERT ...............')
   WHEN (SELECT id_book ................) IS NOT NULL THEN     
      execute('UPDATE ................')
END
[/code]
Co lepsze argument tej funkcji może być dynamiczny, generowany w locie na podstawie zawartości.]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2010-12-07T18:41:44Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2302#p2302</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: SELECT CASE UPDATE/INSERT]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2301#p2301"/>
			<content type="html"><![CDATA[tak
gdy bym chciał użyć funkcji zrobił bym konstrukcje IF ELSE, jednak najlepiej jak by to było w zapytaniu]]></content>
			<author>
				<name><![CDATA[Rogo]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1161</uri>
			</author>
			<updated>2010-12-07T08:30:06Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2301#p2301</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: SELECT CASE UPDATE/INSERT]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2300#p2300"/>
			<content type="html"><![CDATA[Nie wiem czy rozumiem ale chcesz w zależności od tego czy jakieś zapytanie zwraca wynik wykonać update lub insert?]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2010-12-06T18:51:28Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2300#p2300</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[SELECT CASE UPDATE/INSERT]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2299#p2299"/>
			<content type="html"><![CDATA[Witam

Próbuje stworzyć zapytanie które pod określonym warunkiem wywoła UPDATE lub INSERT

SELECT CASE 
   WHEN (SELECT id FROM .........) IS NULL THEN
      (INSERT ...............) 
   WHEN (SELECT id_book ................) IS NOT NULL THEN      
      (UPDATE ................') 
END

Jednak bez powodzenia, wskazywany jest błąd w składni.
ERROR:  syntax error at or near nazwa_tabeli

Czy jest to wykonalne, bo kiedyś słyszałem ,że w PostgreSQL nie da się tego zrobić.
A jeśli się nie da to prosiłbym o podobny lub zbliżony sposób.]]></content>
			<author>
				<name><![CDATA[Rogo]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1161</uri>
			</author>
			<updated>2010-12-06T17:42:00Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2299#p2299</id>
		</entry>
</feed>
