Re: [GENERAL] A script which drops a column - Mailing list pgsql-general

From Bruce Momjian
Subject Re: [GENERAL] A script which drops a column
Date
Msg-id 199911260436.XAA26312@candle.pha.pa.us
Whole thread Raw
In response to A script which drops a column  ("Alain TESIO" <tesio@easynet.fr>)
List pgsql-general
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Hello,
>
> You may be interested by a script which drops a column as this
> feature isn't supported by Postgresql. I guess it could be easier
> and nice in Perl or something similar but I'm using what I know.
>
> The parameters are in that order :
>
> the name of the database
> the table
> the column to drop
>
> Alain
>
> #!/bin/sh
>
> psql -d $1 -c "\d $2" | awk 'BEGIN { keep=1 } /+-/ { keep=1-keep } { if
> (keep) { print } }' | grep -v "\-\-" | grep -v "Table *=" | grep -v " $3 " |
> sed "s/| \([^ ]*\).*/\1/" | tr -s \\012 "," | sed "s/,$//" | sed
> "s/\(.*\)/select \1 into temp tmp_drop_column from $2 ; drop table $2 ;
> select * into $2 from tmp_drop_column;/" > tmp_sql_drop_column
> psql -d $1 -f tmp_sql_drop_column
> rm tmp_sql_drop_column

The fact is that internally this is exactly what we would have to do to
drop a column.  Now that we have temp tables, maybe someone could code
up some C to do this, or just an pg_exec_query_dest() call to do the
job.


--
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

pgsql-general by date:

Previous
From: "Alain TESIO"
Date:
Subject: A script which drops a column
Next
From: Mike Mascari
Date:
Subject: Re: [GENERAL] drop/rename table and transactions