473,385 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

Nov 22 '05 #1
5 8765
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Bill | last post by:
In an effort to improve the speed of queries against my main table, I'll be indexing a column whose data type is varchar(50). Would I be better off (better performance) if I changed the column's...
5
by: dmhendricks | last post by:
Greetings, I have a question. I work on some SQL2k/ASP.NET apps at work. My predacessor, who created the databases/tables seemed to have liked to use 'char' for all text fields. Is there a...
10
by: Techie | last post by:
what's the difference of the two data types?
7
by: James o'konnor | last post by:
hello. i have the next for create one table into db2 CREATE TABLE "MYSQUEMA"."TABLADEMO" ( "ID" INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY ( START WITH +0 INCREMENT BY +1 MINVALUE +0...
6
by: mike | last post by:
so I keep optimizing my fields down to the minimum character length necessary i.e., varchar(15), then I find out a month later its gotta get bigger, then a few months later, bigger again, etc. ...
1
by: RGow | last post by:
Hi, I'd like to know whether there is a way to alter the data type of a VARCHAR FOR BIT DATA column to be simply a VARCHAR column? I executed an ALTER TABLE statement, similar to, ALTER TABLE...
0
Krishna Ladwa
by: Krishna Ladwa | last post by:
In Sql Server 2000 Version, I found that no Notification message box appears when converting text column to varchar but the data gets truncated to the given size for the varchar. Whereas it appears...
4
by: Nick Chan | last post by:
all these while i've only used varchar for any string i heard from my ex-boss that char helps speed up searches. is that true? so there are these: 1) char with index 2) char without index...
0
by: maheshmohta | last post by:
Background Often while remodeling legacy application, one of the important tasks for the architects is to have an optimum usage of storage capabilities of database. Most of the legacy applications...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.