ALTER_STATISTICS(7pg18)
๐ ALTER STATISTICS ๐
okay bestie, this one's from the PostgreSQL 18.6 Documentation and it's literally called ALTER_STATISTICS โ yes it's a whole page about changing the definition of an extended statistics object. iykyk. ๐
โจ NAME โจ
ALTER_STATISTICS โ change the definition of an extended statistics object. that's the whole job. periodt.
๐ธ 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 | DEFAULT }
look at her. four little glow-ups she can do. ๐
๐ฆ DESCRIPTION ๐ฆ
so ALTER STATISTICS changes the parameters of an existing extended statistics object. that's it, that's the vibe. and here's the cute part: any parameters you did not specifically set in your ALTER STATISTICS command just... keep their prior settings. no surprise resets. she's not gonna touch what you didn't ask her to touch. ๐ซถ
now, the rules. you must own the statistics object to use ALTER STATISTICS. no owning, no altering, sorry babe.
want to change a statistics object's schema? you also need CREATE privilege on the new schema. yes, both. it's giving "two forms of ID at the club." ๐ญ
want to alter the owner? you need to be able to SET ROLE to the new owning role, and that role must have CREATE privilege on the statistics object's schema. and why so strict, you ask? because these restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the statistics object. like, the shortcut can't be more powerful than the long way. that's the whole point. ๐
ngl there's one little loophole though: a superuser can alter ownership of any statistics object anyway. main character energy, obviously. ๐
โจ PARAMETERS โจ
nameโ the name (optionally schema-qualified) of the statistics object you're about to alter. gotta know who we're talking about. ๐new_ownerโ the user name of the new owner of the statistics object. new parent, new vibe.new_nameโ the new name for the statistics object. rebranding era. โจnew_schemaโ the new schema for the statistics object. moving out, getting a new address. ๐new_targetโ the statistic-gathering target for this statistics object for subsequentANALYZEoperations. here's the tea: the target can be set in the range0to10000. set it toDEFAULTto revert to using the system default statistics target (default_statistics_target). oh and heads up โ setting it to a value of-1is an obsolete way spelling to get the same outcome. lowkey don't do that, it's giving 2010. ๐ for more information on the use of statistics by the PostgreSQL query planner, refer to Section 14.2.
๐ COMPATIBILITY ๐
there is no ALTER STATISTICS command in the SQL standard. we made this one ourselves. it's a PostgreSQL original. ๐
๐ SEE ALSO ๐
CREATE STATISTICS(CREATE_STATISTICS(7)) โ where the baby statistics objects come from ๐ผDROP STATISTICS(DROP_STATISTICS(7)) โ for when it's time to say goodbye ๐
and that's the whole page, bestie!! you ate. go forth and alter responsibly. ๐ซถโจ
this masterpiece is from PostgreSQL 18.6, dated 2026 โ drink some water, hydrate, and remember: you're doing amazing. ๐๐ง๐ธ
๐ฆ where this page comes from
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms