pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feeddrop column?
8+ messages / 7 participants
[nested] [flat]
* drop column?
@ 2002-01-23 19:54 Jodi Kanter <jkanter@virginia.edu>
0 siblings, 4 replies; 8+ messages in thread
From: Jodi Kanter @ 2002-01-23 19:54 UTC (permalink / raw)
To: pgsql-admin
I cannot seem to locate any documentation about removing a column that I just added to a table. There is no data in that particular column but there is in the rest of the table.
Can I remove this column or will I need to drop the entire table and restore from backup?
Thanks
Jodi
_______________________________
Jodi L Kanter
BioInformatics Database Administrator
University of Virginia
(434) 924-2846
jkanter@virginia.edu
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: drop column?
@ 2002-01-23 20:25 Nick Fankhauser <nickf@ontko.com>
parent: Jodi Kanter <jkanter@virginia.edu>
3 siblings, 0 replies; 8+ messages in thread
From: Nick Fankhauser @ 2002-01-23 20:25 UTC (permalink / raw)
To: Jodi Kanter <jkanter@virginia.edu>; pgsql-admin
>Can I remove this column or will I need to drop the entire table and
restore from backup?
There's not a "remove column" option for alter table, but you may be able to
get around restoring by renaming the existing table, creating a replacement
the way you want it to look, & then copy from the old to new using "insert
into table newtable (col1,col2) values (select col1,col2 from oldtable);"
-Nick
--------------------------------------------------------------------------
Nick Fankhauser nickf@ontko.com Phone 1.765.935.4283 Fax 1.765.962.9788
Ray Ontko & Co. Software Consulting Services http://www.ontko.com/
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: drop column?
@ 2002-01-23 20:29 Phill Kenoyer <pgsql@c0de.net>
parent: Jodi Kanter <jkanter@virginia.edu>
3 siblings, 0 replies; 8+ messages in thread
From: Phill Kenoyer @ 2002-01-23 20:29 UTC (permalink / raw)
To: Jodi Kanter <jkanter@virginia.edu>; +Cc: pgsql-admin
This is something I have been wanting for a long time. The ability to
update or drop a column from a table.
Right now you have to select the columns you want into a temp table and
drop the working table and rename the temp table to the working table.
|On 020123 12:15
|Jodi Kanter (jkanter@virginia.edu) wrote the following...
|
|I cannot seem to locate any documentation about removing a column that I just added to a table. There is no data in that particular column but there is in the rest of the table.
|Can I remove this column or will I need to drop the entire table and restore from backup?
|Thanks
|Jodi
|_______________________________
|Jodi L Kanter
|BioInformatics Database Administrator
|University of Virginia
|(434) 924-2846
|jkanter@virginia.edu
--
BOFH Reason of the day: not properly grounded, please bury computer
_ | _
(_()(|('.|)('||.|()|`|(
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: drop column?
@ 2002-01-23 20:43 bangh <banghe@baileylink.net>
parent: Jodi Kanter <jkanter@virginia.edu>
3 siblings, 0 replies; 8+ messages in thread
From: bangh @ 2002-01-23 20:43 UTC (permalink / raw)
To: Jodi Kanter <jkanter@virginia.edu>; +Cc: pgsql-admin
Probably not, but I don't the new version.
There are some ways you can do for this prupose.
Create a new table in that database without that columns. you can do
this very easily:
1. pg_dump -t table_name -s your_dbname > anyname.dump
the switch -s means without data, schem only. it is a very simple
ascii file and readable
2. using some edit tool to open file anyname.dump and remove the columns
you don't want and change the table name as a new one like "table_new"
and do:
3. cat anyname.dump | psql your_dbname
4. psql your_db_name
psql> insert into table_new select field1, field2, ... from ori_table;
psql> drop ori_table;
psql> alter table rename table_new ori_table;
Then it is done.
PS. for safe, dump your entire database first
Banghe
Jodi Kanter wrote:
> I cannot seem to locate any documentation about removing a column that
> I just added to a table. There is no data in that particular column
> but there is in the rest of the table.Can I remove this column or will
> I need to drop the entire table and restore from backup?ThanksJodi
> _______________________________
>
>
> Jodi L Kanter
> BioInformatics Database Administrator
> University of Virginia
> (434) 924-2846
> jkanter@virginia.edu
>
> <?xml:namespace prefix = o ns =
> "urn:schemas-microsoft-com:office:office" />
>
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: drop column?
@ 2002-01-24 01:57 lonh SENG <slonh@camgsm.com.kh>
parent: Jodi Kanter <jkanter@virginia.edu>
3 siblings, 0 replies; 8+ messages in thread
From: lonh SENG @ 2002-01-24 01:57 UTC (permalink / raw)
To: Jodi Kanter <jkanter@virginia.edu>; pgsql-admin
Jodi,
Of course, we should have 'alter table .... drop column ....' statement.
>Can I remove this column or will I need to drop the entire table and
restore from backup?
You can do as following:
select fields_you_want_to_keep into new_table from old_table.
Make sure that this statement execute successfully. Then drop the old table
and change table name (alter table ... rename to ...).
I am a newbie of postgres.
lonh
----- Original Message -----
From: Jodi Kanter
To: Postgres Admin List
Sent: Thursday, January 24, 2002 2:54 AM
Subject: [ADMIN] drop column?
I cannot seem to locate any documentation about removing a column that I
just added to a table. There is no data in that particular column but there
is in the rest of the table.
Can I remove this column or will I need to drop the entire table and restore
from backup?
Thanks
Jodi
_______________________________
Jodi L Kanter
BioInformatics Database Administrator
University of Virginia
(434) 924-2846
jkanter@virginia.edu
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: drop column
@ 2003-12-30 14:04 A.Bhuvaneswaran <bhuvan@symonds.net>
parent: Ashok Chauhan <ashok@kalculate.com>
0 siblings, 1 reply; 8+ messages in thread
From: A.Bhuvaneswaran @ 2003-12-30 14:04 UTC (permalink / raw)
To: Ashok Chauhan <ashok@kalculate.com>; +Cc: pgsql-admin
> A command for remove the column but it not work
> it gives parse error
> ALTER TABLE tablename DROP COLUMN fieldname;
drop column feature is implemented since 7.3. So, you please check out
your version.
regards,
bhuvaneswaran
Attachments:
signature.asc (application/pgp-signature, 231B) download
^ permalink raw reply [nested|flat] 8+ messages in thread
* drop column
@ 2003-12-30 17:07 Ashok Chauhan <ashok@kalculate.com>
0 siblings, 1 reply; 8+ messages in thread
From: Ashok Chauhan @ 2003-12-30 17:07 UTC (permalink / raw)
To: pgsql-admin
hello
i have a problem to drop a column.
on postgresql site (link)
http://www.postgresql.org/docs/current/interactive/ddl-alter.html#AEN2124
A command for remove the column but it not work
it gives parse error
ALTER TABLE tablename DROP COLUMN fieldname;
plz. help me
Ashok
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: drop column
@ 2003-12-31 11:34 Ashok Chauhan <ashok@kalculate.com>
parent: A.Bhuvaneswaran <bhuvan@symonds.net>
0 siblings, 0 replies; 8+ messages in thread
From: Ashok Chauhan @ 2003-12-31 11:34 UTC (permalink / raw)
To: pgsql-admin
On Tue, 2003-12-30 at 14:04, A.Bhuvaneswaran wrote:
> > A command for remove the column but it not work
> > it gives parse error
> > ALTER TABLE tablename DROP COLUMN fieldname;
>
> drop column feature is implemented since 7.3. So, you please check out
> your version.
>
> regards,
> bhuvaneswaran
hello
thanks for reply.
yes i am using 7.2 version.
so any other option except drop the table and re-create it.
Ashok
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2003-12-31 11:34 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-01-23 19:54 drop column? Jodi Kanter <jkanter@virginia.edu>
2002-01-23 20:25 ` Nick Fankhauser <nickf@ontko.com>
2002-01-23 20:29 ` Phill Kenoyer <pgsql@c0de.net>
2002-01-23 20:43 ` bangh <banghe@baileylink.net>
2002-01-24 01:57 ` lonh SENG <slonh@camgsm.com.kh>
2003-12-30 17:07 drop column Ashok Chauhan <ashok@kalculate.com>
2003-12-30 14:04 ` Re: drop column A.Bhuvaneswaran <bhuvan@symonds.net>
2003-12-31 11:34 ` Re: drop column Ashok Chauhan <ashok@kalculate.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