Re: How to convert integer to boolean in insert

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to convert integer to boolean in insert
Date: 2009-04-06 17:51:15
Message-ID: grdfei$dqc$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alvaro Herrera wrote on 06.04.2009 19:39:
>> If that is a one-time thing, why not create the table with banned as an
>> integer column and another boolean column (if your INSERTs are properly
>> listing the column names), then after the import update the boolean to
>> the casted integer value, drop the integer and rename the boolean?
>
> Actually it seems it would be better to create the table with only the
> integer column, and later use ALTER TABLE / TYPE to change it.
> Something like
>
> CREATE TABLE foo (banned integer);
>
> -- run inserts
>
> ALTER TABLE foo ALTER banned TYPE bool USING banned::bool;
>
> That way you don't end up with half a table of dead tuples.

Yes I was worrying about that as well.

Didn't know about the cast in the ALTER statement ;)

Pretty cool.

Thomas

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2009-04-06 18:10:42 Re: copy from with trigger
Previous Message Alvaro Herrera 2009-04-06 17:48:47 Re: Number Conversion Function