DROP_STATISTICS(7pg13)
π DROP STATISTICS β the "bye bestie" command
So this is straight out of the PostgreSQL 13.23 Documentation (section 7pg13, yes bestie we're in the man pages now), and honestly? It's giving cleanup era. β¨
πΈ NAME πΈ
DROP_STATISTICS β remove extended statistics. That's it, that's the vibe. You made stats objects, now you're deleting them. Closure. π¦
β¨ SYNOPSIS β¨
DROP STATISTICS [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]
Look at that syntax, it ate. π
π DESCRIPTION π
Okay so DROP STATISTICS removes statistics object(s) from the database. Boom, gone, no cap. π₯
But here's the thing β you can't just be out here dropping stats that aren't yours. Only the statistics object's owner, the schema owner, or a superuser can drop a statistics object. That's the rules. Know your role, respect the role. π
π PARAMETERS π
IF EXISTSβ Do not throw an error if the statistics object does not exist. A notice is issued in this case. Basically it's the "no worries if not" of SQL β instead of screaming at you, it just quietly leaves a little notice. π«Άnameβ The name (optionally schema-qualified) of the statistics object to drop. You can be allpublic.somethingabout it or just use the short name, your call bestie. πΈCASCADERESTRICTβ These key words do not have any effect, since there are no dependencies on statistics. Yeahβ¦ they're literally just there for the aesthetic. They don't do anything. β¨ Nothing. Zero. Nada. But you can type them, and honestly? Slay for the consistency. π
π EXAMPLES π
Okay so say you wanna destroy two statistics objects in different schemas, and you don't want it to fail if they don't exist. Here's the move:
DROP STATISTICS IF EXISTS
accounting.users_uid_creation,
public.grants_user_role;
Two schemas, two stats objects, one command, zero drama. Main character energy. π
π¦ COMPATIBILITY π¦
There is no DROP STATISTICS command in the SQL standard. So likeβ¦ this is a PostgreSQL thing. It's exclusive. Iykyk. π§
π SEE ALSO π
ALTER STATISTICS(ALTER_STATISTICS(7))CREATE STATISTICS(CREATE_STATISTICS(7))
Go read those too, bestie β the whole glow-up journey, from CREATE to ALTER to, wellβ¦ here. πβ
Ngl, this one's short and sweet. No warnings, no gotchas, just vibes and a clean deletion. π
Signing off from the PostgreSQL 13.23 docs, dated 2025 β DROP STATISTICS(7), and that's a wrap. ππ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms