Обсуждение: Yet one more question

Поиск
Список
Период
Сортировка

Yet one more question

От
"Josh Berkus"
Дата:
Folks,

ALTER TABLE won't work until 7.1.  CUrrently, I have a table
that needs one small change, but it's refrenced as a foriegn
key by 7 other tables.  Any suggestions on how I can make
the table change without having to drop and re-create 8
tables?

-Josh Berkus


Re: Yet one more question

От
Josh Berkus
Дата:
Justin,

> How do you do the "drop and create" of tables?

1. Save table definition as text.

2. Create a duplicate of the table definition as "temp_table"

3. INSERT all of the table records into the temp_table

4. DROP the existing table

5. Re-CREATE the table with the altered definition.

6. INSERT the rows from the temp_table back into the table.

Of course, this process fails to preserve SERIAL keys, FORIEGN KEYS,
etc. and is somewhat labor intensive.  ANybody create a script to do
this dynamically?

> I use pg_dump -d <dbname> > something.sql
> 
> Then I use vi/sed/something-else to modify the schema in the dumped
> file,
> then reload it into postgreSQL with psql -e <dbname> < something.sql >
> /dev/null

Thanks.  SOunds like a good alternate strategy, although it still blows
away our test data.  I'd also need to see if our functions survive the
dump ...
                -Josh Berkus
-- 
______AGLIO DATABASE SOLUTIONS___________________________                                       Josh Berkus  Complete
informationtechnology      josh@agliodbs.com   and data management solutions       (415) 436-9166  for law firms, small
businesses      fax  436-0137   and non-profit organizations.       pager 338-4078                               San
Francisco