Re: How to convert integer to boolean in insert

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Thomas Kellerer <spam_eater(at)gmx(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to convert integer to boolean in insert
Date: 2009-04-06 17:39:13
Message-ID: 20090406173912.GB4525@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thomas Kellerer wrote:

> 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.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2009-04-06 17:41:58 Re: copy from with trigger
Previous Message Emanuel Calvo Franco 2009-04-06 17:35:05 Re: [COMMITTERS]