Re: Patch to add support of "IF NOT EXISTS" to others "CREATE" statements

From: Tom Dunstan <pgsql(at)tomd(dot)cc>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: fabriziomello(at)gmail(dot)com, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch to add support of "IF NOT EXISTS" to others "CREATE" statements
Date: 2013-06-13 02:35:52
Message-ID: CAPPfruwU=szxfegAmRmfjDQ4rJ-iaQSEaOqmmS4p9VpKtDuULg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 13 June 2013 04:30, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:

> I'm wondering where "IF NOT EXISTS" and "OR REPLACE" will meet.
>

CREATE OR REPLACE (or ALTER / UPDATE ?) would definitely be useful for
enums, where it would be nice if we could teach an ORM to generate DDL
based on the current values of the enum in code, and know that after the
operation had completed, the database enum type matched the code enum type.
I don't think a sequence of ALTER TYPE ADD VALUE IF NOT EXISTS quite does
the trick, as it doesn't guarantee that the db enum is in the same order as
the code enum, which may or may not be important. I'd expect a CREATE OR
ALTER for enums to raise an error if any of the elements were out of order.

Currently to get to a known state for enums you have to write manual
migration scripts, and while that tends to be how I roll anyway, often when
starting projects in rails / grails / hibernate etc people rely on db
schemas generated by the framework as it lets them prototype with less
mucking around. It would be nice for those frameworks to be able to
generate enum types in a known state.

Cheers

Tom

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Brendan Jurd 2013-06-13 03:00:51 Re: [PATCH] Exorcise "zero-dimensional" arrays (Was: Re: Should array_length() Return NULL)
Previous Message Darren Duncan 2013-06-13 02:10:01 Re: [PATCH] Exorcise "zero-dimensional" arrays (Was: Re: Should array_length() Return NULL)