From: | Igor Neyman <ineyman(at)perceptron(dot)com> |
---|---|
To: | alecinvan <e_toner(at)hotmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: how to pass tablename to a function |
Date: | 2014-09-05 14:50:47 |
Message-ID: | A76B25F2823E954C9E45E32FA49D70ECAB2AC0A1@mail.corp.perceptron.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of alecinvan
Sent: Thursday, September 04, 2014 6:28 PM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] how to pass tablename to a function
Hi, All
I like to pass the tablename to function but not using execute clause, here is my script
CREATE OR REPLACE FUNCTION functions.pgsql_event_unpack_batch(IN _tbl text, IN jobid bigint, IN jobtime timestamp with time zone, IN startid bigint, IN stopid bigint)
RETURNS TABLE(events bigint, errors bigint[]) AS $BODY$ BEGIN
RETURN QUERY
WITH
unpacking (raw_id, time, userid, eventtype, pagename, userhost, application, status, error)
AS (
select
id as raw_id,
(up).time,
(up).userid,
coalesce((up).eventtype, ''),
coalesce((up).pagename, ''),
(up).userhostaddress as userhost,
coalesce((up).application, ''),
(up).status,
(up).error
from(
select id,
functions.python_events_unpack(event_object) up
from _tbl
where id between startid and stopid
) a
where (up).userid is not NULL
)
I want to pass the _tbl to the select query integrated in the unpacking(), how can I make it?
thanks
Alec
You can't.
You have to use dynamic sql (EXECUTE).
Regards,
Igor Neyman
From | Date | Subject | |
---|---|---|---|
Next Message | Kevin Grittner | 2014-09-05 15:03:49 | Re: Exists subquery in an update ignores the effects of the update itself |
Previous Message | John McKown | 2014-09-05 14:46:11 | Re: Employee modeling question |