<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum PostgreSQL - Problem z select case]]></title>
	<link rel="self" href="http://forum.postgresql.org.pl/extern.php?action=feed&amp;tid=392&amp;type=atom"/>
	<updated>2010-02-04T12:30:23Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.postgresql.org.pl/viewtopic.php?id=392</id>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z select case]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1796#p1796"/>
			<content type="html"><![CDATA[Problem rozwiązany, może komuś się przyda.

select slowo,opis,dodal
from  f.slownik_slowo  where slowo like 
(
	select 
		 case 
				when zmienna='-1' then '%'
				when  (SUM(CHAR_LENGTH(zmienna)))>1 then ('%'||upper(zmienna)||'%')
				else null
				end
				) 
				group by slowo,opis, dodal
Pozdrawiam.]]></content>
			<author>
				<name><![CDATA[gintor]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=959</uri>
			</author>
			<updated>2010-02-04T12:30:23Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1796#p1796</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z select case]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1794#p1794"/>
			<content type="html"><![CDATA[Cześć,
przykładowo przy zmiennej 'ło'
wynika ma być taki:

słońce - opis 1 
słońce - opis 2
słoń - opis 
słony - opis 

czyli mamy dwa razy te same słowo, ale różne opisy.]]></content>
			<author>
				<name><![CDATA[gintor]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=959</uri>
			</author>
			<updated>2010-02-04T06:56:19Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1794#p1794</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z select case]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1791#p1791"/>
			<content type="html"><![CDATA[Ale co ma się pojawić w wyniku jak słowo ma dwa opisy?]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2010-02-03T15:08:32Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1791#p1791</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Problem z select case]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=1790#p1790"/>
			<content type="html"><![CDATA[Cześć, 

mam następujący problem. Mam dwie tabele 
slownik_slowo ( id, slowo) oraz
slownik_opis (id,opis)

slownik_slowo.id=slownik_opis.id

Działa mi 1 warunek i 3, problem mam z drugim, 


select 
case
	when	'z1'='-1' then slowo
	when (SUM(CHAR_LENGTH('z1')))>1  then ( select slowo from f.slownik_opis a join f.slownik_slowo b on a.id=b.id  where b.slowo like '%z1%')
	else null 
	---(select slowo from f.slownik_opis a join f.slownik_slowo b on a.id=b.id  where b.slowo like '-1')
	end, 
case 
	when	'z1'='-1' then opis
	when  (SUM(CHAR_LENGTH('z1')))>1 then ( select opis from f.slownik_opis a join f.slownik_slowo b on a.id=b.id  where b.slowo like '%z1%')
	else  null
	--( select opis from f.slownik_opis a join f.slownik_slowo b on a.id=b.id  where b.slowo like '-1')
	end, 
case 
	when	'z1'='-1' then dodal
	when (SUM(CHAR_LENGTH('z1')))>1 then ( select dodal from f.slownik_opis a join f.slownik_slowo b on a.id=b.id  where b.slowo like '%z1%')
	 else null
	 -- (select dodal from f.slownik_opis a join f.slownik_slowo b on a.id=b.id  where b.slowo like '-1')
	end 

from f.slownik_opis a join f.slownik_slowo b on a.id=b.id where slowo like (upper('%-1%'))
group by b.slowo,a.opis, dodal


ERROR:  more than one row returned by a subquery used as an expression

Problem jest jak jedno slowo(czyli zmienna z1) ma dwa opisy.
Jak zbudować funkcję żeby dało się wykonać ten warunek ? Niestety odpada CREATE FUNCTION.

Jakieś podpowiedzi ?]]></content>
			<author>
				<name><![CDATA[gintor]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=959</uri>
			</author>
			<updated>2010-02-03T13:02:23Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=1790#p1790</id>
		</entry>
</feed>
