pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Roger Moloney <ramoloney@hotmail.com>
To: pgsql-interfaces@postgresql.org
Subject: ecpg: HOW TO READ RECORD ??
Date: Thu, 23 Aug 2007 14:55:10 +0000
Message-ID: <BAY115-F20EFAFF003B91E1FD30DE7AFD60@phx.gbl> (raw)

Hi,

We use ecpg (embedded sql) and plpgsql (postgres functions).

I'm having trouble trying to get embedded SQL to read the result of a 
plpgsql function which returns RECORD or SETOF RECORD.

Does anyone have an example of this ?  I don't see it in the ecpg source 
examples or in the ecpg manual.

/* following is an example of plpgsql to illustrate the data being returned 
*/

/* type defined for the record that the function will return to avoid using 
column list */
create type tp_GetPerson as (
  person_name    char(40),
  person_age      smallint
);

/* this function returns zero or more tp_GetPerson records */
create function p_GetPersonByDept (pperson_dept integer)
  returns SETOF tp_GetPerson as
$$
declare
  v_record tp_GetPerson%ROWTYPE;
begin
  for v_record in
    select person_name, person_age from person where person_dept = 
pperson_dept
  loop
     return next v_record;
  end loop;
  return;
end
$$
language 'plpgsql';

WHAT SHOULD THE ECPG PROGRAM LOOK LIKE THAT CAN  READ THE DATA RETURNED ?

thanks,
RML

_________________________________________________________________
Download the latest version of Windows Live Messenger NOW! 
http://get.live.com/en-za/messenger/overview




view thread (2+ messages)  latest in thread

Message-ID: <BAY115-F20EFAFF003B91E1FD30DE7AFD60@phx.gbl>
Permalink:  ../BAY115-F20EFAFF003B91E1FD30DE7AFD60@phx.gbl/
Also on:    postgresql.org/message-id/BAY115-F20EFAFF003B91E1FD30DE7AFD60@phx.gbl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: ramoloney@hotmail.com
  Subject: Re: ecpg: HOW TO READ RECORD ??
  In-Reply-To: <BAY115-F20EFAFF003B91E1FD30DE7AFD60@phx.gbl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox