Re: Pl/pgsql function

Lists: pgsql-general
From: Nick Raj <nickrajjain(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Pl/pgsql function
Date: 2011-06-04 14:04:25
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-general

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


From: Rob Sargent <robjsargent(at)gmail(dot)com>
To: Nick Raj <nickrajjain(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Pl/pgsql function
Date: 2011-06-04 14:22:16
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-general

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>


From: "David Johnston" <polobo(at)yahoo(dot)com>
To: "'Nick Raj'" <nickrajjain(at)gmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Pl/pgsql function
Date: 2011-06-04 15:44:17
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-general

>>From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Nick Raj
>>Sent: Saturday, June 04, 2011 10:04 AM
>>To: pgsql-general(at)postgresql(dot)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.