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;