Обсуждение: Need help using function

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

Need help using function

От
"Bob Pawley"
Дата:
Hi
 
I want to try using functions but I am having trouble understanding return.
 
This is the function -
CREATE OR REPLACE FUNCTION p_id.ip_orient_3()
  RETURNS integer AS
$BODY$
 
 Begin
 
 Insert into fluids (fluid_id) values ('1') ;

  End;
  $BODY$
  LANGUAGE 'plpgsql' VOLATILE
  COST 100;
ALTER FUNCTION p_id.ip_orient_3() OWNER TO postgres;
 
This is how I am calling the function -
 
 select p_id.ip_orient_3();
 
The error message - "control reached end of function without RETURN"
 
I have attempted adding - Return integer; to the end of the function with no success.
 
Can anyone help me??
 
Bob
 

Re: Need help using function

От
John R Pierce
Дата:
Bob Pawley wrote:
> Hi
>
> I want to try using functions but I am having trouble understanding
> return.
>
> ...
>
> The error message - "control reached end of function without RETURN"
>
> I have attempted adding - Return integer; to the end of the function
> with no success.
>


I'd try adding
     RETURN 1;
or similar,  before the END;



Re: Need help using function

От
"Bob Pawley"
Дата:
That worked.

However, perhaps I don't understand the idea of a function.

If the , in this case ('1'),  was in fact an unknown variable what would the
return be?

Bob
----- Original Message -----
From: "John R Pierce" <pierce@hogranch.com>
To: "Bob Pawley" <rjpawley@shaw.ca>; <pgsql-general@postgresql.org>
Sent: Friday, June 26, 2009 10:15 AM
Subject: Re: [GENERAL] Need help using function


> Bob Pawley wrote:
>> Hi
>>  I want to try using functions but I am having trouble understanding
>> return.
>>  ...
>>  The error message - "control reached end of function without RETURN"
>>  I have attempted adding - Return integer; to the end of the function
>> with no success.
>>
>
>
> I'd try adding
>     RETURN 1;  or similar,  before the END;
>
>


Re: Need help using function

От
"Jonah H. Harris"
Дата:
On Fri, Jun 26, 2009 at 1:28 PM, Bob Pawley <rjpawley@shaw.ca> wrote:
However, perhaps I don't understand the idea of a function.

--
Jonah H. Harris, Senior DBA
myYearbook.com

Re: Need help using function

От
"Bob Pawley"
Дата:
Ok, it seem that is not what I am seeking.
 
I have a triggered function that works quite well on an insert into a table.
 
What I would like to do is trigger that same function when conditions are updated in an other table.
 
I'm trying to avoid having to copy the whole function over to an update trigger. 
 
An other method would be to have the function triggered by a separate table and then insert (then delete) a value into that table to trigger the function - but I am hoping someone can come up with another way?
 
Bob
 
----- Original Message -----
Sent: Friday, June 26, 2009 10:30 AM
Subject: Re: [GENERAL] Need help using function

On Fri, Jun 26, 2009 at 1:28 PM, Bob Pawley <rjpawley@shaw.ca> wrote:
However, perhaps I don't understand the idea of a function.

--
Jonah H. Harris, Senior DBA
myYearbook.com