By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,384 Members | 845 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,384 IT Pros & Developers. It's quick & easy.

Resize varchar column

P: n/a
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 ma*******@postgresql.org

Nov 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Bruno Wolff III said:
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.
I'll take a look at the system catalogs - thanks for the tip.
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).


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

Nov 22 '05 #2

P: n/a
Bruno Wolff III wrote:
catalogs. I don't know the exact details of what to do, but the instructions
should be in the archives (multiple times).


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 ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 22 '05 #3

P: n/a
On Wed, 4 Feb 2004, John Sidney-Woollett wrote:
Bruno Wolff III said:
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.


I'll take a look at the system catalogs - thanks for the tip.
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).


I was hoping to avoid a column drop and recreate.

Thanks for the info.


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 ma*******@postgresql.org)

Nov 22 '05 #4

P: n/a
On Wednesday 04 February 2004 16:00, John Sidney-Woollett wrote:
Bruno Wolff III said:
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.


I'll take a look at the system catalogs - thanks for the tip.
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).


I was hoping to avoid a column drop and recreate.


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 ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 22 '05 #5

P: n/a
Richard Huxton said:
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.


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

Nov 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.