Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old November 22nd, 2005, 08:51 AM
John Sidney-Woollett
Guest
 
Posts: n/a
Default Resize varchar column

Is it possible to alter a table to resize a varchar column? The PG docs
indicate lots of uses for "alter table T alter column C..." but not one
that allows the changing of the type (or same type, new size).

This is possible in Oracle (provided you are increasing the column size).

Is there a way to resize the column without having to drop or recreate the
table or column?

Thanks

John Sidney-Woollett

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org




  #2  
Old November 22nd, 2005, 08:51 AM
John Sidney-Woollett
Guest
 
Posts: n/a
Default Re: Resize varchar column

Bruno Wolff III said:[color=blue]
> In general (in 7.4.x) you can change data types using add, drop, rename
> and a query to copy/translate the data. This will have the side effect of
> making the updated column the last column when using * to refer to the
> table's columns.[/color]

I'll take a look at the system catalogs - thanks for the tip.
[color=blue]
> It is possible to change the size of varchar data by updating the system
> catalogs. I don't know the exact details of what to do, but the
> instructions should be in the archives (multiple times).[/color]

I was hoping to avoid a column drop and recreate.

Thanks for the info.

John Sidney-Woollett



---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

  #3  
Old November 22nd, 2005, 08:51 AM
Dirk Försterling
Guest
 
Posts: n/a
Default Re: Resize varchar column

Bruno Wolff III wrote:[color=blue]
> catalogs. I don't know the exact details of what to do, but the instructions
> should be in the archives (multiple times).[/color]

Maybe. But how to find this? Any query on archives.postgresql.org
returns just

"Sorry, but search returned no results.

Try to produce less restrictive search query"

for me (with varying search time).

-dirk

--
D i r k F "o r s t e r l i n g
r@zorbla.de http://r@zorbla.de/
-------------
"Diese Rekursionen sind nicht mit den Haaren herbeigezaubert" - R.K.


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

  #4  
Old November 22nd, 2005, 08:51 AM
scott.marlowe
Guest
 
Posts: n/a
Default Re: Resize varchar column

On Wed, 4 Feb 2004, John Sidney-Woollett wrote:
[color=blue]
> Bruno Wolff III said:[color=green]
> > In general (in 7.4.x) you can change data types using add, drop, rename
> > and a query to copy/translate the data. This will have the side effect of
> > making the updated column the last column when using * to refer to the
> > table's columns.[/color]
>
> I'll take a look at the system catalogs - thanks for the tip.
>[color=green]
> > It is possible to change the size of varchar data by updating the system
> > catalogs. I don't know the exact details of what to do, but the
> > instructions should be in the archives (multiple times).[/color]
>
> I was hoping to avoid a column drop and recreate.
>
> Thanks for the info.[/color]

There is a way to do it. I don't recall it off my head, it has to do with
tweaking the system catalogs directly. That said, I would practice on a
test database, backup the live database, and cross my fingers and use a
chicken foot to make sure you don't scram your database, as playing with
system catalogs by hand is not something that's guaranteed to be a nice
happy safe thing. But as messing with the system catalogs go, this is one
of the easier things to do.

It should be in the list archives somewhere, and should probably be an
admin faq by now.


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

  #5  
Old November 22nd, 2005, 08:51 AM
Richard Huxton
Guest
 
Posts: n/a
Default Re: Resize varchar column

On Wednesday 04 February 2004 16:00, John Sidney-Woollett wrote:[color=blue]
> Bruno Wolff III said:[color=green]
> > In general (in 7.4.x) you can change data types using add, drop, rename
> > and a query to copy/translate the data. This will have the side effect of
> > making the updated column the last column when using * to refer to the
> > table's columns.[/color]
>
> I'll take a look at the system catalogs - thanks for the tip.
>[color=green]
> > It is possible to change the size of varchar data by updating the system
> > catalogs. I don't know the exact details of what to do, but the
> > instructions should be in the archives (multiple times).[/color]
>
> I was hoping to avoid a column drop and recreate.[/color]

The message (one of them anyway) you want is:

http://archives.postgresql.org/pgsql...0/msg01208.php

Try and find something more recent though, in case anything important has
changed. Oh, and do take Tom's advice about the backup.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

  #6  
Old November 22nd, 2005, 08:51 AM
John Sidney-Woollett
Guest
 
Posts: n/a
Default Re: Resize varchar column

Richard Huxton said:[color=blue]
> The message (one of them anyway) you want is:
>
> http://archives.postgresql.org/pgsql...0/msg01208.php
>
> Try and find something more recent though, in case anything important has
> changed. Oh, and do take Tom's advice about the backup.[/color]

Thanks, that's great.

It would be nice if there was a command available that would do simple
column resizes (upwards), or even data type changes (assuming no implied
data truncation), ie

alter table T alter column X varchar(x);

where x is the new size, and x > old size;

In fact, looking at your URL above (and using the technique explained), it
may be possible to create a function that does this.

I wonder if it works, though, if there is an index on the column...

Anyway, this time, I dropped and recreated the table as this is a test
system. But reinstating all the objects that referenced that table was a
pain!

Thanks again.

John Sidney-Woollett

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.