1

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;

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

Not yet possible, you have to wait for 9.0
1

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.