how to pass tablename to a function

From: alecinvan <e_toner(at)hotmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: how to pass tablename to a function
Date: 2014-09-04 22:28:22
Message-ID: 1409869702971-5817861.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

--
View this message in context: http://postgresql.1045698.n5.nabble.com/how-to-pass-tablename-to-a-function-tp5817861.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message A L. 2014-09-04 23:42:45 how to pass tablename to a function
Previous Message Adrian Klaver 2014-09-04 20:42:58 Re: Re: [ADMIN] Cannot retrieve images inserted through VB and odbc, after a table reorganization.