2

I have a query :

update (select tmp."table1" as tmpid, 
               del."table1" as  delid 
          from "table1_TMP" tmp ,
               "table1_DEL" del 
         where del."table2" = tmp."table2" and 
               del."REFSEQNO" = tmp."REFSEQNO")
   set tmpid = delid;

This query runs in oracle without any problem.

How can I modify this query to run on Postgresql?

3
  • +1 because I did not know Oracle has updateable inline views. That is cool. Commented Dec 14, 2012 at 12:30
  • Yeah, that's really impressive, especially on a join view. Commented Dec 14, 2012 at 13:16
  • 1
    Very efficient too, but limited to views where there are sufficient constraints in place to guarantee that each row in the update target cannot join to multiple rows. There was, and maybe still is, an undocumented optimiser hint BYPASS_UJVC to prevent the checking prior to execution, but it didn't work in at least one version and recently MERGE is preferred where the constraints are not in place. Oracle will also DELETE on a join view -- the child rows are deleted, which makes sense of course. Commented Dec 15, 2012 at 22:55

1 Answer 1

3

I think this would do it.

update "table1_TMP" tmp
set "table1" = del."table1"
from "table1_DEL" del
where del."table2" = tmp."table2" and
      del."REFSEQNO" = tmp."REFSEQNO"
Sign up to request clarification or add additional context in comments.

1 Comment

Yup. They key is that postgresql allows a from clause in an update statement. postgresql.org/docs/current/static/sql-update.html

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.