我可以创建复杂类型的AWS Redshift UDF

时间:2017-06-20 15:52:57

标签: python amazon-redshift

我想创建复杂类型的AWS UDF功能。 AWS UDF正文部分支持Python语言。我在Python中创建了body部分函数,​​这个函数运行良好。但是,我在AWS redshift上运行了以下代码,我收到了一条错误消息。

Adding jquery to execute a wrap:

$(‘p’).wrap(‘<span class=”newclass” />’);

will result in:

<span class=”newclass”>
<p>This is a paragraph.</p>
</span>

<span class=”newclass”>
<p>This is a paragraph.</p>
</span>

<span class=”newclass”>
<p>This is a paragraph.</p>
</span>



Substitute the .wrap for .wrapAll.

$(‘p’).wrapAll(‘<span class=”newclass” />’);

will result in:

<span class=”newclass”>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</span>



Now try out .wrapInner.

$(‘p’).wrapInner(‘<span class=”newclass” />’);

will result in:

<p><span class=”newclass”>This is a paragraph.</span></p>
<p><span class=”newclass”>This is a paragraph.</span></p>
<p><span class=”newclass”>This is a paragraph.</span></p>

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题。以下代码为我工作

CREATE OR REPLACE FUNCTION abc(EffDt character varying, Pay character varying)
RETURNS character varying AS

def payDate(EffDt,Pay):
  from dateutil.parser import parse
  import datetime
  from datetime import timedelta
  if len(EffDt)>0 and len(Pay)>0:
         dt=parse(EffDt)
         if dt.month and dt.day==1:
           print(dt.month)
           print(dt.day)
           NewDate=dt
         else:
           if Pay=="Weekely":
                  value=datetime.date(dt.year, dt.month, dt.day).weekday() 
                  print(value)
                  if value==1:
                       NewDate= dt + timedelta(days=1)
                  elif value==2:
                        NewDate = dt
                  elif value==3:
                    NewDate=dt+timedelta(days=6)
                    print(NewDate)
                  elif value==4:
                         NewDate=dt+timedelta(days=5)
                  elif value==5:
                     NewDate=dt+timedelta(days=4)
                  elif value==6:
                    NewDate=dt+timedelta(days=3)
                  elif value==7:
                   NewDate=dt+timedelta(days=2)
                  else :
                    pass
           if Pay=="Monthly":
              strvalue=dt.strftime(''%Y/%m/%d'')
              if strvalue[:2]=="15":
                strDate=str(dt.month)+"/16/"+str(dt.year)
                NewDate=parse(strDate)
              elif strvalue[:3]=="01":
                NewDate=dt
              else :
               strDate=str(dt.month+1)+"/01/"+str(dt.year)
               NewDate=parse(strDate)
               print(NewDate)

  else :
      NewDateValue="1/1/1990"
      NewDate=parse(NewDateValue)


  mm=NewDate.month
  yyyy=NewDate.year 
  print(yyyy)
  if len(str(mm))==1:
      mm="0"+str(mm)
  dd=NewDate.day 
  if len(str(dd))==1:
      dd="0"+str(dd)
  _date=str(yyyy) +str(mm)+str(dd)
  print(yyyy)
  print(mm)
  print(dd)
  return _date

return payDate(EffDt, Pay) 
LANGUAGE plpythonu STABLE;