From: | Derrick Betts <list(at)blueaxis(dot)com> |
---|---|
To: | "pgsql-novice(at)postgresql(dot)org >> \"pgsql-novice(at)postgresql(dot)org\"" <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: How do I insert a record into a table? |
Date: | 2007-06-01 19:30:19 |
Message-ID: | 466073CB.9060708@blueaxis.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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;
From | Date | Subject | |
---|---|---|---|
Next Message | Brian Hurt | 2007-06-01 19:54:43 | Re: How do I insert a record into a table? |
Previous Message | Richard Broersma Jr | 2007-06-01 19:06:38 | Re: How do I insert a record into a table? |