ALTER_STATISTICS(7pg16)
Hey bestie! π Welcome to the ALTER_STATISTICS page from PostgreSQL 16.15, also known as the 7pg16 manual. We're about to dive into literally how to change the definition of an extended statistics object. It's giving main character energy, fr fr. β¨
πΈ NAME πΈ
Okay so literally, ALTER_STATISTICS is the command that changes the definition of an extended statistics object. No cap, that's the whole vibe. π
β¨ SYNOPSIS β¨
ALTER STATISTICS name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER STATISTICS name RENAME TO new_name
ALTER STATISTICS name SET SCHEMA new_schema
ALTER STATISTICS name SET STATISTICS new_target
π¦ DESCRIPTION π¦
Bestie, ALTER STATISTICS changes the parameters of an existing extended statistics object. Any parameters you don't specifically set in the ALTER STATISTICS command just retain their prior settings, periodt. π
Okay, so permissions check, because yes, we gotta go there. You must own the statistics object to use ALTER STATISTICS. To change a statistics object's schema, you must also have CREATE privilege on the new schema. To alter the owner, you must be able to SET ROLE to the new owning role, and that role must have CREATE privilege on the statistics object's schema. (These restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the statistics object. However, a superuser can alter ownership of any statistics object anyway.) Like, the system is just making sure you're not doing sneaky stuff, iykyk. π₯
π PARAMETERS π
nameβ The name (optionally schema-qualified) of the statistics object to be altered. Like, you gotta tell it which object you're messing with, bestie. πnew_ownerβ The user name of the new owner of the statistics object. Slay, new owner vibes. πnew_nameβ The new name for the statistics object. Fresh name, fresh identity, we love a rebrand. πnew_schemaβ The new schema for the statistics object. Moving it to a new neighborhood, iconic. π‘new_targetβ The statistic-gathering target for this statistics object for subsequentANALYZEoperations. The target can be set in the range 0 to 10000; alternatively, set it to-1to revert to using the maximum of the statistics target of the referenced columns, if set, or the system default statistics target (default_statistics_target). For more information on the use of statistics by the PostgreSQL query planner, refer to Section 14.2. Literally so much flexibility, we love options. π―
π§ COMPATIBILITY π§
There is no ALTER STATISTICS command in the SQL standard. Like, the SQL standard didn't get the memo, and honestly, that's its loss. π
β SEE ALSO β
CREATE STATISTICS (CREATE_STATISTICS(7)), DROP STATISTICS (DROP_STATISTICS(7)) β go check these out, they're iconic. β¨
This page is from PostgreSQL 16.15, dated 2026. So yeah, it's literally from the future or something. Stay slay, bestie! π πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-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