Re: [GENERAL] Add a NOT NULL column with default only during add

2013-08-02 Thread Boszormenyi Zoltan
2013-08-02 16:58 keltezéssel, Tom Lane írta: Adrian Klaver writes: No I am saying that in the ALTER data_type case the column is not being created and USING is working on data(assuming data had actually been entered already) that exists. What you propose is a two step process, create a column a

Re: [GENERAL] Add a NOT NULL column with default only during add

2013-08-02 Thread Tom Lane
Adrian Klaver writes: > No I am saying that in the ALTER data_type case the column is not being > created and USING is working on data(assuming data had actually been > entered already) that exists. What you propose is a two step process, > create a column and then fill it with a default value

Re: [GENERAL] Add a NOT NULL column with default only during add

2013-08-02 Thread Adrian Klaver
On 08/02/2013 01:03 AM, BladeOfLight16 wrote: On Thu, Aug 1, 2013 at 8:15 PM, Adrian Klaver mailto:adrian.kla...@gmail.com>> wrote: What you want is a default that only works during ALTER ADD COLUMN. At that point though, there is no data added and DEFAULT only works with INSERTS. Yo

Re: [GENERAL] Add a NOT NULL column with default only during add

2013-08-02 Thread Vik Fearing
On 08/02/2013 10:03 AM, BladeOfLight16 wrote: > So my question is effectively this: Is there an existing, equivalent, > single DDL statement to the following hypothetical SQL? > > ALTER TABLE x > ADD COLUMN data2 VARCHAR(10) NOT NULL USING 'foo'; > > where "USING" here would indicate the same thing

Re: [GENERAL] Add a NOT NULL column with default only during add

2013-08-02 Thread BladeOfLight16
On Thu, Aug 1, 2013 at 8:15 PM, Adrian Klaver wrote: > What you want is a default that only works during ALTER ADD COLUMN. At > that point though, there is no data added and DEFAULT only works with > INSERTS. Your example of USING with ALTER data_type works because there > actually may be rows alr

Re: [GENERAL] Add a NOT NULL column with default only during add

2013-08-01 Thread Adrian Klaver
On 08/01/2013 04:59 PM, BladeOfLight16 wrote: On Thu, Aug 1, 2013 at 7:53 PM, Adrian Klaver mailto:adrian.kla...@gmail.com>> wrote: It fails because ALTER TABLE x ADD COLUMN data2 VARCHAR(10) NOT NULL DEFAULT 'foo', end in , instead of ; You have to add the column before y

Re: [GENERAL] Add a NOT NULL column with default only during add

2013-08-01 Thread BladeOfLight16
On Thu, Aug 1, 2013 at 7:53 PM, Adrian Klaver wrote: > It fails because > > ALTER TABLE x > ADD COLUMN data2 VARCHAR(10) NOT NULL DEFAULT 'foo', > > end in , instead of ; > > You have to add the column before you can alter it. > =/ That's the way I have it in the SQL Fiddle sample I provided. I w

Re: [GENERAL] Add a NOT NULL column with default only during add

2013-08-01 Thread Adrian Klaver
On 08/01/2013 04:25 PM, BladeOfLight16 wrote: On Thu, Aug 1, 2013 at 7:10 PM, Richard Broersma mailto:richard.broer...@gmail.com>> wrote: Notice : http://www.postgresql.org/docs/9.3/static/sql-altertable.html After you add a column to your table, you can latter *alter* this colum

Re: [GENERAL] Add a NOT NULL column with default only during add

2013-08-01 Thread BladeOfLight16
On Thu, Aug 1, 2013 at 7:10 PM, Richard Broersma wrote: > Notice : > http://www.postgresql.org/docs/9.3/static/sql-altertable.html > After you add a column to your table, you can latter *alter* this column > to add, change, or remove the default expression. There's no need add > temporary column

Re: [GENERAL] Add a NOT NULL column with default only during add

2013-08-01 Thread Richard Broersma
Notice : http://www.postgresql.org/docs/9.3/static/sql-altertable.html After you add a column to your table, you can latter *alter* this column to add, change, or remove the default expression. There's no need add temporary columns to manage this kind of change. In fact, all of the DDL that you'v

[GENERAL] Add a NOT NULL column with default only during add

2013-08-01 Thread BladeOfLight16
When I want to add a new column with a NOT NULL constraint, I need to specify a DEFAULT to avoid violations. However, I don't always want to keep that DEFAULT; going forward after the initial add, I want an error to occur if there are inserts where this data is missing. So I have to DROP DEFAULT on