Re:

From: "A(dot) Kretschmer" <akretschmer(at)despammed(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re:
Date: 2005-08-19 15:58:56
Message-ID: 20050819155856.GA3429@webserv.wug-glas.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

am 19.08.2005, um 16:38:20 +0100 mailte Nigel Horne folgendes:
> On Fri, 2005-08-19 at 16:30, Adam Witney wrote:
> > > I can't work out from that how to return more than one value.
> >
> > Hi Nigel,
> >
> > Add SETOF to your function like so:
> >
> > CREATE TABLE test (id int);
> > INSERT INTO test VALUES(1);
> > INSERT INTO test VALUES(2);
> >
> > CREATE FUNCTION test_func() RETURNS SETOF integer AS '
> > SELECT id FROM test;
> > ' LANGUAGE SQL;
>
> What if one value I want to return is an integer, and another one is a
> string?

Create a new type. For instance: (sorry, comments in german)

,----
| create type saldeninfo as (kontonr bigint,
| zugang numeric(10,2),
| abgang numeric(10,2),
| zeitpunkt timestamp,
| saldo numeric(10,2));
|
| --
| -- Nun die Funktion, sie ist in der Sprache SQL definiert
| --
| create or replace function saldeninfo( int ) returns setof saldeninfo as
| $$
| select reset_saldo();
| select kontonr, case when typ = 'Z' then wert when typ = 'A' then NULL END as zugang,
| case when typ = 'Z' then NULL when typ = 'A' then wert end as abgang,
| ts,
| prev_saldo(get_saldo(typ, wert))::numeric(10,2) as saldo
| from buchungen where kontonr = $1;
| $$
| language sql;
|
`----

Regards, Andreas
--
Andreas Kretschmer (Kontakt: siehe Header)
Heynitz: 035242/47212, D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
=== Schollglas Unternehmensgruppe ===

In response to

  • Re: at 2005-08-19 15:38:20 from Nigel Horne

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tony Caduto 2005-08-19 16:11:31 question about plpgsql replace function
Previous Message Adam Witney 2005-08-19 15:41:40 Re: http://www.postgresql.org/docs/8.0/static/xfunc-sql.html