Re: oracle to postgres

From: BladeOfLight16 <bladeoflight16(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: oracle to postgres
Date: 2015-02-04 01:08:06
Message-ID: CA+=1U=WLL4pQBg=Y5Mw098s--eXmieL5xKSVj7gpj=KW76GFbA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>
> BEGIN
> EXECUTE IMMEDIATE 'DROP TABLE CONTAINER';
> EXCEPTION
> WHEN OTHERS THEN
> IF SQLCODE != -942 THEN
> RAISE;
> END IF;
> END;
>

Jim nailed it. In PostgreSQL, this is just

DROP TABLE IF EXISTS CONTAINER;

One line. No dynamic SQL, exception block, or even a block at all. It also
issues a notice when the table does not exist, so if you're watching the
messages, you'll know what happened.

On top of that, you don't have the weird edge cases to think about that
even make using an EXCEPTION block for conditional DROP a good idea in
Oracle. The reason you use an EXCEPTION block in Oracle is because 1)
there's no atomic way of both checking for existence and performing the
drop, and 2) because DDL always emits an implicit commit, checking for
existence and then DROPping creates a race condition if you could have
multiple sessions performing the DROP. (Of course, I've always questioned
the wisdom of setting your system up where you could have multiple sessions
doing that at the same time.) In PostgreSQL, both these problems are
solved. In PG, DDL does *not* automatically emit a commit. DDL happens
inside a transaction (assuming a transaction is initialized). This means
you can perform multiple DDL operations in a single transaction and even
roll them back. And for a single command that does both, you have the IF
EXISTS option.

I love PostgreSQL. It makes the simple things simple, and the hard things
possible and easier.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message BladeOfLight16 2015-02-04 02:33:36 Re: [GENERAL] How do I bump a row to the front of sort efficiently
Previous Message David Steele 2015-02-04 00:40:03 Re: Fwd: [GENERAL] 4B row limit for CLOB tables