开发者

Can Postgres do this? (Specifically without a function() construct)?

开发者 https://www.devze.com 2022-12-24 15:29 出处:网络
I have some oracle calls that I am porting.开发者_如何学运维Today I came across this code which looks like \"procedural\" language, but is not declared in a function or anything... My question is:Can

I have some oracle calls that I am porting.开发者_如何学运维 Today I came across this code which looks like "procedural" language, but is not declared in a function or anything... My question is: Can postgres handle this in this form? What form does this need to be in?

DECLARE
BEGIN
   IF :start_time IS NULL OR
      :start_date IS NULL OR
      :end_time IS NULL OR
      :end_date IS NULL  THEN
         INSERT INTO ARPSPACE_AVAILABILITY
            (ARP_ARPSPACE_NM, ASA_TIME_ID, ASA_START_DT, ASA_END_DT)
         SELECT :arpspace_name,
                 1,
                 ASP.ASP_START_DT,
                 ASP.ASP_STOP_DT
           FROM ASP 
          WHERE EXISTS
             (SELECT ARP.ARP_ARPSPACE_NM
                FROM ARPSPACE ARP
               WHERE ARP.ARP_ARPSPACE_NM = :arpspace_name);
   END IF;
END;


No, not yet without declaring a function. In version 9.0 (soon in Beta) this will be possible: http://developer.postgresql.org/pgdocs/postgres/sql-do.html


Short answer is yes, if you can declare a function. See plpgsql from the manual for details.


Why not do this (assuming :labels are prepared query parameters)?

     INSERT INTO ARPSPACE_AVAILABILITY
        (ARP_ARPSPACE_NM, ASA_TIME_ID, ASA_START_DT, ASA_END_DT)
     SELECT :arpspace_name,
             1,
             ASP.ASP_START_DT,
             ASP.ASP_STOP_DT
       FROM ASP 
      WHERE EXISTS
         (SELECT ARP.ARP_ARPSPACE_NM
            FROM ARPSPACE ARP
           WHERE ARP.ARP_ARPSPACE_NM = :arpspace_name)
      AND  (:start_time IS NULL OR
            :start_date IS NULL OR
            :end_time IS NULL OR
            :end_date IS NULL);
0

精彩评论

暂无评论...
验证码 换一张
取 消