function return update count - Mailing list pgsql-general

From Kevin Duffy
Subject function return update count
Date
Msg-id CAHCyeW04BVWnW1DszCps0+o0Q3Juodqw8WEPjK8LrNpx+beNqw@mail.gmail.com
Whole thread Raw
Responses Re: function return update count
List pgsql-general
Hello:

I am try to get a function to return the count of the rows updated within the function.
As in the following, I wan the number of rows updated to be returned.

This is a simple update, other update statements that I need to write will be complicated.

CREATE OR REPLACE FUNCTION est_idio_return_stats_update()
  RETURNS integer AS

'
update est_idiosyncratic_return_stats set delta_avg_60 = avg_60 - period_61_return,  delta_avg_last_24 = avg_last_24 - period_61_return, delta_avg_last_18 = avg_last_18 - period_61_return,
         delta_avg_last_12 = avg_last_12 - period_61_return,  delta_avg_last_6 = avg_last_06 - period_61_return ;
'

  LANGUAGE SQL ;

The above returns the following:
ERROR:  return type mismatch in function declared to return integer
DETAIL:  Function's final statement must be SELECT or INSERT/UPDATE/DELETE RETURNING.
CONTEXT:  SQL function "est_idio_return_stats_update"

********** Error **********

ERROR: return type mismatch in function declared to return integer
SQL state: 42P13
Detail: Function's final statement must be SELECT or INSERT/UPDATE/DELETE RETURNING.
Context: SQL function "est_idio_return_stats_update"


Thanks for your kind assistance.


KD

pgsql-general by date:

Previous
From: Scott Marlowe
Date:
Subject: Re: Running multiple versions
Next
From: Stefan Keller
Date:
Subject: Re: Vacuum and Large Objects