DROP_STATISTICS(7pg13)

πŸ“¦ version 13.23, in opensuse-leap 16.0

πŸ’… 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 all public.something about it or just use the short name, your call bestie. 🌸
  • CASCADE
  • RESTRICT β€” 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 πŸ‘€

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