10/22/2023 0 Comments Cascade delete postgresNext, make sure that your PostgreSQL database server is running. Start by creating a project directory where you can put the files you'll create throughout this guide: mkdir cascading-deletes-demo. Without that, I would not have checked the constraints again. Create a new database and project directory. If the foreign key declaration is not there, of course this can't work properly. TABLE "formula" CONSTRAINT "parent_fkey" FOREIGN KEY (parent) REFERENCES formula(id) ON DELETE CASCADE "parent_fkey" FOREIGN KEY (parent) REFERENCES formula(id) ON DELETE CASCADE I checked the constraints of my relation again using \d+ formula. Or does DELETE only count the deleted rows without the cascade? The number of deleted rows should be higher. Now I wonder, why the delete count is also 25800000 rows. DELETE FROM formula WHERE mass >= 1000.0 AND id = parent I executed the following query, to delete the rows. I know, that there are rows, which not match the condition id = parent, but should be deleted anyways, because the already mentioned constraint. ON DELETE CASCADE constraint, I expected to delete more than 25800000 rows. Now I know, that 25800000 rows match the conditions. I executed following query, to get the (minimum) amount of deleted rows: SELECT COUNT(*) FROM formula WHERE mass >= 1000.0 AND id = parent Parent bigint NOT NULL REFERENCES id ON DELETE CASCADEĪfter importing some data, I wanted to delete all rows, with masses >= 1000.0 matching the condition id = parent. Mass numeric(13,8) NOT NULL CHECK (mass > 0), I created a relation as following: CREATE TABLE formula ( ON DELETE CASCADE constraint worked properly. I'm not sure, if the deletion of rows of my psql relation with a REFERENCE.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |