pgstac icon indicating copy to clipboard operation
pgstac copied to clipboard

pypgstac function for deleting collections/items

Open hrodmn opened this issue 2 years ago • 7 comments

Have you considered adding pypgstac functions for deleting collections and items? I see some SQL functions that seem to do this: delete_collection delete_item

What do you think about adding delete_collections and delete_items methods for the Loader class?

hrodmn avatar Oct 20 '22 11:10 hrodmn

these methods would be really useful

slesaad avatar Nov 21 '22 18:11 slesaad

I would also like these methods.

ryanjdillon avatar Jan 03 '23 11:01 ryanjdillon

@hrodmn I'm not sure that those are quite appropriate for the Loader class as the Loader is designed to take a file to ingest it. This is definitely something that I would consider exposing otherwise though. What were you thinking for the API? pypgstac delete collection mycollection

bitner avatar Jan 03 '23 21:01 bitner

This would be great to have.

I'm struggling to do it via PG Admin... I've resorted to truncating the table and re-indexing, which won't work for large collections.

alexgleith avatar Oct 02 '23 04:10 alexgleith

Did we get anywhere with this?

I'd also like to know if we can 'truncate' a collection, even by connecting to postgres.

alexgleith avatar Jan 15 '24 02:01 alexgleith

Oh, nevermind, this is easy when connected to postgres. Just need to update search path, so the local functions are able to be found.

SET search_path = pgstac, public;
DELETE from items where collection = 'collection_name';

alexgleith avatar Jan 15 '24 02:01 alexgleith

Confirming that @alexgleith 's tip works. If you forget to run the SET command first you may see an error similar to

NOTICE:  Updating partition stats 2024-05-29 15:53:23.220797+00
ERROR:  relation "partition_sys_meta" does not exist

davidcalhoun avatar May 29 '24 16:05 davidcalhoun