Re: Changing a table column datatype

From: <marshall(at)perilith(dot)com>
To: psql novice <psql_novice(at)operamail(dot)com>
Cc: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Changing a table column datatype
Date: 2003-05-13 01:48:24
Message-ID: Pine.LNX.4.33.0305122146080.6185-100000@perilith.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hmmm... Maybe I haven't explained what I'm trying to do clearly.

I don't wish to insert new fqdn values into this table, only copy
the contents of one column (`mycol') into another column (`mycol_new').
Am I missing something here?

On Tue, 13 May 2003, psql novice wrote:

> Hi Marshall,
>
> based on the error msg your getting back from postgres, your column
> fqdn is set to 'not null'. therefore you must enter something into
> that field when trying to insert a new record.
>
> going off your example, you could do it like this:
>
> insert into mytable (fqdn, mycol_new) select fqdn, mycol from mytable;
>
>
> ----- Original Message -----
> From: <marshall(at)perilith(dot)com>
> Date: Mon, 12 May 2003 20:18:57 -0400 (EDT)
> To: <pgsql-novice(at)postgresql(dot)org>
> Subject: [NOVICE] Changing a table column datatype
>
> > Hello,
> >
> > This has been asked before, but the responses weren't clear enough
> > for me to understand.
> >
> > I have a table `mytable' with an attribute `mycol' of datatype char(4) and
> > I'd like to change it to varchar(20). Mycol is populated by two values -
> > NULLs and four element chars. What I've tried thusfar:
> >
> > db=> ALTER TABLE mytable ADD COLUMN mycol_new VARCHAR(20);
> > ALTER TABLE
> > db=> INSERT INTO mytable (mycol_new) SELECT mycol FROM mytable;
> > ERROR: ExecInsert: Fail to add null value in not null attribute fqdn
> >
> > The `fqdn' attribute is another column in mytable.
> >
> > So is it the case that INSERT doesn't like inserting NULL values? Is
> > there another way to do this?
> >
> > I'm using PostgreSQL 7.3.2.
> >
> > TIA!
> >
> > -mt
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the unregister command
> > (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>
>
> --
> ____________________________________________
> http://www.operamail.com
> Get OperaMail Premium today - USD 29.99/year
>
>
> Powered by Outblaze
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Terence Ng 2003-05-13 03:12:41 Re: Multilingual database
Previous Message psql novice 2003-05-13 01:06:45 Re: Changing a table column datatype