Search code examples
sqloracle-databasepostgresqlpostgresql-9.1greenplum

Postgres date-numeric not working in function


Can anyone help me to resolve the issue ??

    CREATE OR REPLACE FUNCTION func_maj_get_new_user(in_date numeric)
      RETURNS integer AS
    $BODY$
    declare

    count_newusr integer;

    begin


    SELECT count(a.app_uid) 
      INTO count_newusr 
    FROM 
    (SELECT s_start.app_uid 
       FROM devdba.s_maj_sdk_bs s_start 
      WHERE s_start.app_rts::date = current_date - in_date
       AND (s_start.app_uid,s_start.app_key) NOT IN(SELECT app_uid,app_key 
                                                      FROM datemp.maj_usr_mstr)
     )a;

return count_newusr;
end;
$BODY$
  LANGUAGE plpgsql VOLATILE;

The below function throws an error like ,

ERROR: operator does not exist: date - text LINE 1: ..._start WHERE s_start.app_rts::date = current_date - $1 AND...


Solution

  • in_date must be integer

    current_date - in_date::integer
    

    Or just pass it as integer

    func_maj_get_new_user(in_date integer)