Postgres - Passing table name as parameter and store result in file

前端 未结 1 1987
滥情空心
滥情空心 2021-01-27 22:29
    Create Or Replace Function totalRecords (tablename TEXT) Returns integer as $total$
    Declare
      total integer;

      Begin
       select count  (*)  into  tot         


        
相关标签:
1条回答
  • 2021-01-27 23:16

    I sorted the issue this way

     Begin
     execute 'select count(*) from ' ||tablename||
    ' where cast(date_dimension_year || ''-'' || date_dimension_month || ''-''||date_dimension_day as date) 
    not between (current_date - interval ''13 months'') and current_date' into total ;
    

    I had to assign the integer total towards the end and proper closing of quotation (') worked for me.( I just pasted a portion of the function where i was getting issue)

    Thanks for all your help.

    0 讨论(0)
提交回复
热议问题