Re: Building a record in a function

From: Richard Huxton <dev(at)archonet(dot)com>
To: Robert Fitzpatrick <lists(at)webtent(dot)net>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Building a record in a function
Date: 2007-02-27 17:47:46
Message-ID: 45E46EC2.8020801@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Robert Fitzpatrick wrote:
> Haven't done a whole lot of plsql returning records, only those based on
> a query. I was wondering, can I build a record from the results of the
> query using other values for some fields in the record? I know 'return
> next' requires a record and want to build my own record to include some
> argument values in the record. I have my record declared and my query
> results in that record. So, how do you construct a record in a function?
> Below is my work...
>
> period := $1;
> rep := $2;
> FOR dateval IN SELECT (period::date+(s||'month')::interval)::date from generate_series(0,11)s
> loop
> SELECT INTO picks
> COUNT(public.view_pick_1_data.units)::numeric AS units,
CURRENT_DATE AS "date",
'x'::text AS some_text_field

That's the simplest way.
Alternatively, you can use CREATE TYPE to make the required row-type and
fill a variable of that type.
--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jorge Godoy 2007-02-27 17:52:24 Re: How to debug this crash?
Previous Message Tom Lane 2007-02-27 17:29:51 Re: pg_dump and restore problem with function as DEFAULT-Constraint