pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Changing datatype of a column
3+ messages / 3 participants
[nested] [flat]

* Changing datatype of a column
@ 2001-06-26 07:41 Ilan Fait <ilan@iweb.com>
  2001-06-26 14:43 ` Re: Changing datatype of a column Peter Eisentraut <peter_e@gmx.net>
  2001-06-26 16:28 ` Re: Changing datatype of a column Jason Earl <jdearl@yahoo.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Ilan Fait @ 2001-06-26 07:41 UTC (permalink / raw)
  To: pgsql-sql


              Hi,

              I would like to Know if there any way (and what is the command
for that)  to convert a column datatype
              from int4 to numeric(11)  of an existing table that have data
in it?
              
         
             Thanks,
             Ilan

  
_________________________________________
ILAN FAIT
Tel: 972-9-9519133  Ex.247    iWeb Technologies
Fax: 972-9-9519134                91 Medinat Ha'Yehudim St.
                                                     Herzliya 46120 IL
mailto:ilan@iweb.com    www.iweb.com

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Changing datatype of a column
  2001-06-26 07:41 Changing datatype of a column Ilan Fait <ilan@iweb.com>
@ 2001-06-26 14:43 ` Peter Eisentraut <peter_e@gmx.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Peter Eisentraut @ 2001-06-26 14:43 UTC (permalink / raw)
  To: Ilan Fait <ilan@iweb.com>; +Cc: pgsql-sql

Ilan Fait writes:

>               I would like to Know if there any way (and what is the command
> for that)  to convert a column datatype
>               from int4 to numeric(11)  of an existing table that have data
> in it?

No, you have to recreate the table.

-- 
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Changing datatype of a column
  2001-06-26 07:41 Changing datatype of a column Ilan Fait <ilan@iweb.com>
@ 2001-06-26 16:28 ` Jason Earl <jdearl@yahoo.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Jason Earl @ 2001-06-26 16:28 UTC (permalink / raw)
  To: Ilan Fait <ilan@iweb.com>; pgsql-sql

There is no way to do this directly, but it is a
pretty simple task to do this using SELECT INTO.

Here is a trivial example of how to do this.

First of all let's say you have a table that looks
like this with some values in it:

CREATE TABLE foo (
    num    int
);

processdata=> select * from foo;
 num 
-----
   1
   2
   3
(3 rows)


A simple query using SELECT INTO would give you the
table that you need.

processdata=> select num::numeric(11) as num into bar
from foo;

Here's the results.

processdata=> \d bar
             Table "bar"
 Attribute |     Type      | Modifier 
-----------+---------------+----------
 num       | numeric(11,0) | 

processdata=> select * from bar;
 num 
-----
   1
   2
   3
(3 rows)

You can then drop the original table and use alter
table to change the name of the new table.  You can
also add constraints and whatever else you need.

Hope this is helpful,
Jason
--- Ilan Fait <ilan@iweb.com> wrote:
> 
>               Hi,
> 
>               I would like to Know if there any way
> (and what is the command
> for that)  to convert a column datatype
>               from int4 to numeric(11)  of an
> existing table that have data
> in it?
>               
>          
>              Thanks,
>              Ilan
> 
>   
> _________________________________________
> ILAN FAIT
> Tel: 972-9-9519133  Ex.247    iWeb Technologies
> Fax: 972-9-9519134                91 Medinat
> Ha'Yehudim St.
>                                                     
> Herzliya 46120 IL
> mailto:ilan@iweb.com    www.iweb.com
> 
> 
> 


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-06-26 16:28 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-06-26 07:41 Changing datatype of a column Ilan Fait <ilan@iweb.com>
2001-06-26 14:43 ` Peter Eisentraut <peter_e@gmx.net>
2001-06-26 16:28 ` Jason Earl <jdearl@yahoo.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox