GP創建函數時遇到以下錯誤,想起來上次創相似的函數時也遇到過同樣的問題,卻忘了當時是怎麼解決的,再網上查閱資料,發現這個錯誤的意思應該是函數體中多了不該出現的符號,一直將目光局限於select語句段,檢查了一遍又一遍,甚至按照某個教程刪去了所有無用的空格和換行都沒有用,最後是帶我的同事過來一眼發現問題,記錄一下,免得下次再犯同樣的錯誤QAQ
錯誤描述:[Code: 0, SQL State: 42601] ERROR: syntax error at or near “select”
位置:1077 [Script position: 1081 – 1087]
with tb1 as ( …… ), tb2 as (…… ), select to_char(a.stat_date,'mm/dd') as stat_date,b.part_type,b.factory,coalesce(b.numerator,0) as numerator,coalesce(b.denominator,0) as denominator, case when coalesce(b.denominator,0)=0 then 0 else round(100.0*coalesce(b.numerator,0)/coalesce(b.denominator,0),2) end as ratiofrom tb1 a left join tb2 b on a.stat_date=b.stat_date;
其實就是臨時表和select語句間多了一個逗號,臨時表間需要有”,”分隔,但與select語句間不需要
牢記教訓。