Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2006

    Unanswered: Change varchar size of existing column

    Hello! How do I change the varchar size of an existing column? Here's what I'm trying but doesn't work:

    ALTER TABLE smp.candidato ALTER COLUMN txt_endereco TYPE varchar(100)

    I get this error when I try that:

    ERROR: parser: parse error at or near "TYPE" at character 53

    I also tried without the words TYPE, COLUMN, no joy!
    The column is currently varchar(70), and I want to change it to varchar(100) without losing its data! Please help!

    PostgreSQL 7
    PgAdmin III 1.2.1

  2. #2
    Join Date
    Jun 2004
    Arizona, USA
    PostgreSQL 7 doesn't allow you to alter an existing column's size attributes.

    You'll need to do several steps.

    • Alter the table to add a new temporary varchar column with size 100.
    • copy the data from existing varchar column to the new temp column.
    • Alter the table to drop the existing 70 character column.
    • Alter the table to add the old column name with a size of 100 characters.
    • Copy the data from the temp column to the new column
    • Drop the temp column.

    Beginning with pg version 8, you can directly alter an existing column.
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts