Re: how to pass tablename to a function - Mailing list pgsql-general

From David G Johnston
Subject Re: how to pass tablename to a function
Date
Msg-id 1409876608374-5817871.post@n5.nabble.com
Whole thread Raw
In response to how to pass tablename to a function  (A L. <e_toner@hotmail.com>)
List pgsql-general
alecinvan wrote
> I like to pass the tablename to function but not using execute clause,
> here is my script
>
> [...]
>
> I want to pass the _tbl to the select query integrated in the unpacking(),
> how can I make it?

There is no way to perform a query with an unknown, at design time,
identifier without using EXECUTE.

The recommended way to do this is to use "format()" and dollar-quoting -
v9.1+ required:

v_qry := format(

$qry$
WITH [...]
SELECT id, func(...) FROM %I WHERE id [...]
$qry$

, _tbl

);

RETURN QUERY EXECUTE v_qry;

David J.




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


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: how to pass tablename to a function
Next
From: alecinvan
Date:
Subject: how to pass tablename to a function