chatdesk-ui/storage_v1.19.1/migrations/tenant/0005-add-size-functions.sql

15 lines
367 B
PL/PgSQL

drop function if exists storage.get_size_by_bucket();
CREATE OR REPLACE FUNCTION storage.get_size_by_bucket()
RETURNS TABLE (
size BIGINT,
bucket text
)
LANGUAGE plpgsql
AS $function$
BEGIN
return query
select sum((metadata->>'size')::int) as size, bucket_id as bucket
from "storage".objects
group by bucket_id;
END
$function$;