Re: [GENERAL] Passing RECORD variable from func1() to func2()

2004-09-06 Thread Alvaro Herrera
On Mon, Sep 06, 2004 at 10:39:54PM +0200, Henry Combrinck wrote:

> Can you give an example of what a "named rowtype" is?  Are you refering to
> creating some kind of custom TYPE, and then passing that to
> func2(custom_type_row)?

You can use a table's rowtype, that is, a type that has the name of the
table and the same column types.  Or you can create a "standalone type" with

CREATE TYPE foo AS (f1 int, f2 text, ...)

-- 
Alvaro Herrera ()
"Find a bug in a program, and fix it, and the program will work today.
Show the program how to find and fix a bug, and the program
will work forever" (Oliver Silfridge)


---(end of broadcast)---
TIP 8: explain analyze is your friend



Re: [GENERAL] Passing RECORD variable from func1() to func2()

2004-09-06 Thread Tom Lane
"Henry Combrinck" <[EMAIL PROTECTED]> writes:
> Can you give an example of what a "named rowtype" is?

The result of CREATE TYPE AS, or the row type implicitly created for a
table.  For instance

CREATE TYPE complex AS (r float, i float);

CREATE FUNCTION abs(complex) RETURNS float AS ...

or

CREATE TABLE users (name text, ...);

CREATE FUNCTION foobar(users) RETURNS ...

regards, tom lane

---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [GENERAL] Passing RECORD variable from func1() to func2()

2004-09-06 Thread Henry Combrinck
> "Henry Combrinck" <[EMAIL PROTECTED]> writes:
>> Essentially, I would like to pass a RECORD variable from one function to
>> another using plpgsql:
>
>> func2(record)
>
> You can't declare a plpgsql function that accepts RECORD; this is simply
> not supportable.  (For one thing, which actual record types should such
> a function be considered to match?  It's a nonstarter even at the level
> of function argument resolution, let alone the implementation issues.)
> It has to take some named rowtype, instead.

Thanks for the response.

Can you give an example of what a "named rowtype" is?  Are you refering to
creating some kind of custom TYPE, and then passing that to
func2(custom_type_row)?

Thanks
Henry



This message was sent using MetroWEB's AirMail service.
http://www.metroweb.co.za/ - full access for only R73.
Free Web Accelerator, WebMail, Calendar, Anti-Virus, 
Anti-Spam, 10 emails, 100MB personal webspace, and more!
Phone Now!  086 11 11 440

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [GENERAL] Passing RECORD variable from func1() to func2()

2004-09-06 Thread Tom Lane
"Henry Combrinck" <[EMAIL PROTECTED]> writes:
> Essentially, I would like to pass a RECORD variable from one function to
> another using plpgsql:

> func2(record)

You can't declare a plpgsql function that accepts RECORD; this is simply
not supportable.  (For one thing, which actual record types should such
a function be considered to match?  It's a nonstarter even at the level
of function argument resolution, let alone the implementation issues.)
It has to take some named rowtype, instead.

There are implementation restrictions in 7.4 and before that prevent
plpgsql functions from passing row or record variables to other
functions, so you'd have problems at the calling end as well.
FWIW these restrictions are fixed for 8.0.

regards, tom lane

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faqs/FAQ.html


[GENERAL] Passing RECORD variable from func1() to func2()

2004-09-06 Thread Henry Combrinck
Hello

Hopefully someone can shed some light on the following issue.  After
chatting at irc.freenode.net/#postgresql, without success, this is my last
effort before giving up and using a temp table.

Essentially, I would like to pass a RECORD variable from one function to
another using plpgsql:

func2(record)
rec1 alias for $1
begin
  -- do work on rec1.*
  raise notice ''val1=% val2=%'', rec1.col1, rec1.col2;
end;

func1()
declare
  temprec record;
begin
  for temprec in select * from table1, table2...
  loop
  ...
  select func2(temprec);/* pass temprec row to func2() */
  ...
  end loop;
end;

Then call with:
SELECT FUNC1();

Is this possible?  The docs only speak about RECORD type being used to
*return* rows, but not to pass it.

Any pointers would be appreciated.

Regards
Henry



This message was sent using MetroWEB's AirMail service.
http://www.metroweb.co.za/ - full access for only R73.
Free Web Accelerator, WebMail, Calendar, Anti-Virus, 
Anti-Spam, 10 emails, 100MB personal webspace, and more!
Phone Now!  086 11 11 440

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster