Re: How do I insert a record into a table? - Mailing list pgsql-novice

From Derrick Betts
Subject Re: How do I insert a record into a table?
Date
Msg-id 466073CB.9060708@blueaxis.com
Whole thread Raw
In response to How do I insert a record into a table?  (Brian Hurt <bhurt@janestcapital.com>)
List pgsql-novice
Brian Hurt wrote:

>
> I want to write a query like:
>
> INSERT INTO table SELECT func(args);
>
> where func is defined as:
>
> CREATE OR REPLACE FUNCTION func(args)
> RETURNS table
> AS $_$
>    ...
> $_$ LANGUAGE plpgsql;
>
> Unfortunately, when I try to do this, I get:
>
> ERROR: column "first_column" is of type integer but expression is of
> type record
>

If I understand what you are trying to do then one suggestion would be
to execute everything inside the function.
    SELECT * FROM my_function(args); --(args is an array that looks like
this:  '{tablename,column1,column2,...}'
then:
CREATE OR REPLACE FUNCTION my_function(_varchar)
RETURNS int4 AS
$BODY$
DECLARE
variables alias for $1;

BEGIN

EXECUTE 'INSERT INTO'||variables[0]||'
VALUES('||variables[i]||','||variables[2]||', '|| ... ||')';

RETURN 1;
END
$BODY$
 LANGUAGE 'plpgsql' VOLATILE;






pgsql-novice by date:

Previous
From: Richard Broersma Jr
Date:
Subject: Re: How do I insert a record into a table?
Next
From: Brian Hurt
Date:
Subject: Re: How do I insert a record into a table?