<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum PostgreSQL - Zapytanie o kolumny ?]]></title>
	<link rel="self" href="http://forum.postgresql.org.pl/extern.php?action=feed&amp;tid=186&amp;type=atom"/>
	<updated>2009-04-24T07:54:16Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.postgresql.org.pl/viewtopic.php?id=186</id>
		<entry>
			<title type="html"><![CDATA[Odp: Zapytanie o kolumny ?]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=756#p756"/>
			<content type="html"><![CDATA[Dokładnie o to mi chodziło, dziękuje :)]]></content>
			<author>
				<name><![CDATA[woziu]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=64</uri>
			</author>
			<updated>2009-04-24T07:54:16Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=756#p756</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Zapytanie o kolumny ?]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=754#p754"/>
			<content type="html"><![CDATA[Możesz tak 
[code]
CREATE FUNCTION ex14() RETURNS  SETOF RECORD AS
$$

select nazwisko,imie, opis  from nagrody, osoby where nagrody.opis = 'I Nagroda' AND osoby.idosoby = nagrody.idosoby; ;
$$LANGUAGE 'sql';
[/code]

Ale wywołanie jest trochę bardziej skomplikowane
[code]
select * from ex14() t(nazwisko typ_kolumny_nazwisko, imie typ_kolumny_imie, opis typ_kolumny_opis); 
[/code]

bo dla zwracanego typu record musisz powiedzieć postgresowi podczas co ma wyświetlić. Nazwa t jest tu dowolna w dokumentacji pewnie znajdziesz cos w stylu 'foo' w nawiasach t( ) podajesz cos chcesz z rekordu wyswietlic

Możesz też pokombinować z parametrami OUT funkcji, ewentualnie stworzyć typ recordowy z trzema polami i zwrócić go w funkcji (zamiast 'return setof record')]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2009-04-23T20:28:46Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=754#p754</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Zapytanie o kolumny ?]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=752#p752"/>
			<content type="html"><![CDATA[CREATE FUNCTION ex14() RETURNS  CHARACTER AS 
$$ 

select nazwisko,imie, opis  from nagrody, osoby where nagrody.opis = 'I Nagroda' AND osoby.idosoby = nagrody.idosoby; ; 
$$LANGUAGE 'sql'; 
select * from ex14(); 

BŁĄD:  return type mismatch in function declared to return character
SZCZEGӣY: Final SELECT must return exactly one column.
KONTEKST:  funkcja SQL "ex14"

Dzisiaj przeczytałem komunikat:) Zrobiłem jedną kolumnę w Select, udało się.
select nazwisko  from nagrody, osoby  where nagrody.opis = 'I Nagroda' AND osoby.idosoby = nagrody.idosoby; ; 
Jak zrobić, aby w wyniku funkcji zobaczyć trzy kolumny. 
Nazwisko, imie, opis są tego samego typu.]]></content>
			<author>
				<name><![CDATA[woziu]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=64</uri>
			</author>
			<updated>2009-04-23T13:06:58Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=752#p752</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Zapytanie o kolumny ?]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=732#p732"/>
			<content type="html"><![CDATA[Może zamiast 
[code]
CREATE FUNCTION ex1() RETURNS integer AS 
[/code]
zwracaj bigint
[code]
CREATE FUNCTION ex1() RETURNS bigint AS 
[/code]
Jak podpowiada komunikat błędu]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2009-04-21T16:35:49Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=732#p732</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Zapytanie o kolumny ?]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=730#p730"/>
			<content type="html"><![CDATA[Funkcja agregująca ma za zadanie zliczyć wszystkie wiersze w tabeli osoby.

CREATE FUNCTION ex1() RETURNS integer AS 
$$ 
select count(*)  from osoby 
$$LANGUAGE 'sql';

BŁĄD: return type mismatch in function declared to return integer
Stan SQL:42P13
Szczegóły:Aktualny zwracany typ to bigint.
Kontekst:funkcja SQL "ex1"

Jak rozwiązać te problemy ?

-- Jak robię zapytanie, po kolumnie to wynik dostaję.

CREATE OR REPLACE FUNCTION ex2() 
RETURNS numeric AS $$ 
select sum(brutto)  from zarobki 
$$LANGUAGE 'sql'; 

SELECT * from ex2()]]></content>
			<author>
				<name><![CDATA[woziu]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=64</uri>
			</author>
			<updated>2009-04-21T13:34:05Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=730#p730</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Zapytanie o kolumny ?]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=729#p729"/>
			<content type="html"><![CDATA[Jeżeli tabela osoby ma 7 kolumn robisz funkcje
[code]
CREATE  FUNCTION p() RETURNS
setof osoby 
[/code]
to nie mozesz w tej funkcji wpisac 
[code]
select imie,nazwisko
[/code]
bo "setof osoby" oznacza zbiór wierszy z tabeli osoby obejmujący wszystkie kolumny.
Ale jeśli mam rację i dobrze opisales swoj problem to komunikat bladu powinien byc w stylu
[code]
ERROR:  return type mismatch in function declared to return ...
SZCZEGÓŁY: Final SELECT returns too few columns.
KONTEKST:  SQL function "..."
[/code]]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2009-04-21T10:24:20Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=729#p729</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Zapytanie o kolumny ?]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=728#p728"/>
			<content type="html"><![CDATA[Tabela osoby składa się z 7 kolumn. Kolumna imie i nazwisko są typu char, reszta numeric.
Chyba problem tkwi w typach kolumn i braku deklaracji?
Final SELECT returns character varying instead of numeric at column 1.]]></content>
			<author>
				<name><![CDATA[woziu]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=64</uri>
			</author>
			<updated>2009-04-21T10:18:52Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=728#p728</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Zapytanie o kolumny ?]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=727#p727"/>
			<content type="html"><![CDATA[czy tabela osoby sklada sie tylko z kolumn imie,nazwisko?
W jaki sposób uzywsz funckji agregujacych? podaj jakis przyklad w ktorym wyskakuje ci blad?]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2009-04-20T18:20:22Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=727#p727</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Zapytanie o kolumny ?]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=726#p726"/>
			<content type="html"><![CDATA[Jak uruchamiam, tą funkcję to wszystko dobrze chodzi. 
Jeśli jawnie wypisze kolumny, to wyskakuje mi błąd. -- w kome.
Błąd : return type mismatch in function declared to return osoby

CREATE  FUNCTION p() RETURNS 
setof osoby 
AS 
$$ 
SELECT * FROM osoby   -- Select imie, nazwisko From osoby 
$$ 
LANGUAGE 'sql'; 
SELECT * FROM p();      -- Select imie, nazwisko From p()


Jeszcze mam pytanie o funkcje agregujące, czyli takie jak count(), sum(), max().
Jak uruchamiam  je w podstawowej składni SQL to się wykonują, a jeśli umieszczam je w procedurze to wyskakuje mi błąd.]]></content>
			<author>
				<name><![CDATA[woziu]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=64</uri>
			</author>
			<updated>2009-04-20T15:47:51Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=726#p726</id>
		</entry>
</feed>
