Hello!
PROBLEM; I'm building a web->database IDE and need to be able to drop a table along with everything associated with it.
DESCRIPTION: Often, tables are built with serial identifiers and the like - functions that are tracked by PostgreSQL independently of the table.
If you drop the table, you delete all the data in the table, but the serial_key is preserved as table_field_seq, which must be dropped also to achieve a truly clean "drop".
I need some way to, without knowing previously, what all needs to be dropped in order to drop a table cleanly.
Let's say we have a table "example" with a serial field in it...
We have to somehow get a program to run
drop sequence example_id_seq
drop table example
<? PSEUDO CODE:
$result=pg_exec($connect, "select type, identifier to table example");
For ($i=0; $i<pg_numrows($result); $i++)
{
$row=pg_fetch_array($result, $i);
pg_exec($connect, "drop $row[type] $row[identifier]");
}
?> # END PSEUDO CODE:
OK, it's rough - but is there a way to do this?
-Ben
PROBLEM; I'm building a web->database IDE and need to be able to drop a table along with everything associated with it.
DESCRIPTION: Often, tables are built with serial identifiers and the like - functions that are tracked by PostgreSQL independently of the table.
If you drop the table, you delete all the data in the table, but the serial_key is preserved as table_field_seq, which must be dropped also to achieve a truly clean "drop".
I need some way to, without knowing previously, what all needs to be dropped in order to drop a table cleanly.
Let's say we have a table "example" with a serial field in it...
We have to somehow get a program to run
drop sequence example_id_seq
drop table example
<? PSEUDO CODE:
$result=pg_exec($connect, "select type, identifier to table example");
For ($i=0; $i<pg_numrows($result); $i++)
{
$row=pg_fetch_array($result, $i);
pg_exec($connect, "drop $row[type] $row[identifier]");
}
?> # END PSEUDO CODE:
OK, it's rough - but is there a way to do this?
-Ben