plpgsql - postgresql 9.1 invalid input syntax for type numeric -


i build function little complicated. complicated my standards. when execute code below, using command: select * populate_lt_downside_volatility( '02-sept-2014' , '05-sept-2014' , 5, 'df_1')

i these messages:

notice:  curr_sec_key: s5cond_index notice:  curr_anchor_date.price_date: 2014-09-02  error:  invalid input syntax type numeric: "s5cond_index   " context:  pl/pgsql function "populate_lt_downside_volatility" line 26 @ sql statement  ********** error **********  error: invalid input syntax type numeric: "s5cond_index   " sql state: 22p02 context: pl/pgsql function "populate_lt_downside_volatility" line 26 @ sql statement 

have spent hours cannot figure out. kind assistance requested.

kd

function source code:

-- function: populate_lt_downside_volatility(date, date, integer, character)

create or replace function populate_lt_downside_volatility(start_date date, end_date date, look_back integer, df_series_in character)   returns numeric $body$ declare     ---curr anchor_date     date;    curr_sec_key         character(15);      rtn_ds_vol           numeric(20,12);    max_pricedate        date;    lookback_ln_return   numeric(20,12);    today_date           date  :=  current_date ;       aseckey character(15)[]  :=  array['s5cond_index' ,  's5cons_index' , 's5enrs_index', 's5finl_index', 's5hlth_index', 's5indu_index', 's5inft_index',  's5matr_index' ,  's5tels_index' , 's5util_index' ]  ;    curpricedates cursor  (curr_sec_key  character(15),  sdate date, edate date )              select price_date security_price  sec_key = curr_sec_key  , price_date >= sdate , price_date <= edate  ;      begin     foreach curr_sec_key in array  aseckey  loop    raise notice 'curr_sec_key: %', curr_sec_key ;    curr_anchor_date  in  curpricedates( curr_sec_key , start_date,  end_date ) loop        raise notice 'curr_anchor_date.price_date: %', curr_anchor_date.price_date ;       --  check if date in range.      select sec_key, src_key, price_date ,            lag( ln_return_day_over_day, look_back,  null )  on ( partition sec_key, src_key  order sec_key ,  price_date ) lookback_ln_return      security_price sp      sp.sec_key = curr_sec_key         ,  sp.price_date =  curr_anchor_date.price_date ;       raise notice 'lookback_ln_return: %', lookback_ln_return;      end loop ;   end loop;   end   ; $body$   language plpgsql volatile   cost 100; alter function populate_lt_downside_volatility(date, date, integer, character)   owner postgres; 

table definition:

create table security_price (   sec_key character(15) not null,   price_date date not null,   open_price numeric(18,8),   high_price numeric(18,8),   low_price numeric(18,8),   last_price numeric(18,8),   close_price numeric(18,8),   src_key character(15),   prior_open numeric(18,8),   prior_last numeric(18,8),   ln_open_close_t1 numeric(22,12),   ln_high_low numeric(22,12),   ln_close_open numeric(22,12),   hl_vol_sum_term numeric(22,12),   ln_return_day_over_day numeric(22,12),   constraint pk_security_price primary key (sec_key , price_date ) ) (   oids=false ); alter table security_price   owner postgres; 

select      sec_key, src_key, price_date,      lag( ln_return_day_over_day, look_back,  null )           on ( partition sec_key, src_key  order sec_key ,  price_date )  lookback_ln_return ... 

variable lookback_ln_return of type numeric, while select returns row (i.e. value of pseudo-type record). cannot assign record numeric variable. in such case postgres tries assign first value of record, sec_key of type character(15). unfortunately sec_key not contain proper formatted numeric value, assignment cannot accomplished.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -