Обсуждение: Pl/pgsql function

Поиск
Список
Период
Сортировка

Pl/pgsql function

От
Nick Raj
Дата:
I am implementing some pl/pgsql functions.

Is there any way to change the input
for example- I got some value by $1. I want to modify this value (means split that value), Can we do this and how?

Second thing,
Suppose i defined a function test as

select test('geom',the_geom,time) from tablename
.....
Inside body,
How can i get the tablename inside the body (because i haven't pass table name to function)
......
end

Re: Pl/pgsql function

От
Rob Sargent
Дата:

Nick Raj wrote:
> I am implementing some pl/pgsql functions.
>
> Is there any way to change the input
> for example- I got some value by $1. I want to modify this value
> (means split that value), Can we do this and how?
>
> Second thing,
> Suppose i defined a function test as
>
> select test('geom',the_geom,time) from tablename
> .....
> Inside body,
> How can i get the tablename inside the body (because i haven't pass
> table name to function)
> ......
> end
If 'tablename' has to change then you need to take a look at "dynamic
sql" and the EXECUTE construct.

You can surely manipulate the value of $1 into either other variables or
define it as on OUT parameter if you want the caller to get  a different
value back.  The 8.3 chapter on this is here
<http://www.postgresql.org/docs/8.3/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-ASSIGNMENT>

Re: Pl/pgsql function

От
"David Johnston"
Дата:
>>From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Nick Raj
>>Sent: Saturday, June 04, 2011 10:04 AM
>>To: pgsql-general@postgresql.org
>>Subject: [GENERAL] Pl/pgsql function
>>
>>Second thing,
>>Suppose i defined a function test as
>>
>>select test('geom',the_geom,time) from tablename
>>.....
>>Inside body,
>>How can i get the tablename inside the body (because i haven't pass table
name to function)
>>......
>>end

Not possible; a function only has access to the specific things you provide
it.  If you explain why you want the "tablename" maybe alternatives can be
suggested.  The only time you get access to the table name is when you are
executing the function in the context of a trigger.

David J.