| Goal | This query identifies completely unreserved SQL keywords in PostgreSQL that are used as object identifiers, presenting an aggregated summary of their occurrence counts. As Robert C. Martin notes in Clean Code: "Names in software are 90 percent of what make software readable. You need to take the time to choose them wisely and keep them relevant. Names are too important to treat carelessly. Names should not cause confusion." In PostgreSQL, "there are several different classes of tokens ranging from those that can never be used as an identifier to those that have absolutely no special status in the parser as compared to an ordinary identifier" (PostgreSQL Documentation). Although PostgreSQL permits unreserved keywords (such as status, type, date, value, key, or comment) to be used freely as unquoted identifiers, doing so creates two issues:
|
|---|---|
| Notes | The query uses pg_get_keywords() system catalog information function to find all the keywords that are unreserved in PostgreSQL. In case of each suspected identifier it also presents the status of the keyword in PostgreSQL and information about its usage as column label. The query does not consider objects that are a part of an extension. |
| Type | Problem detection Each row in the result could represent a flaw in the design |
| Reliability | High Few or no false-positive results |
| License | MIT (opens in new tab) |
| Data Source | INFORMATION_SCHEMA+system catalog |
| SQL Query |
|
Fixing Suggestion
Use this aggregated overview to prioritize schema naming cleanup:
- Prioritize high-frequency keywords: Focus first on unreserved keywords with the highest occurrence counts (e.g., numerous columns named status, type, or date) or those known to be strictly reserved in target migration platforms.
- Locate affected objects: Run a detailed inspection query to pinpoint the exact tables, columns, views, or routines using those specific keywords.
- Add domain context: Rename the identifiers to be explicitly domain-specific (for example, changing type to product_type or date to registration_date), updating all dependent views, routines, and application queries accordingly."
Collections
This query belongs to the following collections:
Find problems about names
A selection of queries that return information about the names of database objects. Contains all the types of queries - problem detection, software measure, and general overview.
Find problems automatically
Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not .
| Name | Description |
|---|---|
| Find problems about names | A selection of queries that return information about the names of database objects. Contains all the types of queries - problem detection, software measure, and general overview. |
| Find problems automatically | Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not . |
Categories
This query is classified under the following categories:
Comfortability of database evolution
Queries of this category provide information about the means that influence database evolution.
Naming
Queries of this category provide information about the style of naming.
| Name | Description |
|---|---|
| Comfortability of database evolution | Queries of this category provide information about the means that influence database evolution. |
| Naming | Queries of this category provide information about the style of naming. |
Further reading and related materials:
Perhaps the names are too general. For instance, table name "Table" or column name "column" are at the wrong level of abstraction. The corresponding code smells in case of cleaning code are "N1: Choose Descriptive Names", "N2: Choose Names at the Appropriate Level of Abstraction", "N4: Unambiguous Names", "N7: Names Should Describe Side-Effects". (Robert C. Martin, Clean Code)
Smell "Meaningless name": Sharma, T., Fragkoulis, M., Rizou, S., Bruntink, M. and Spinellis, D.: Smelly relations: measuring and understanding database schema quality. In: Proceedings of the 40th International Conference on Software Engineering: Software Engineering in Practice, pp. 55-64. ACM, (2018).
| Reference |
|---|
| https://www.postgresql.org/docs/current/sql-keywords-appendix.html |
| Perhaps the names are too general. For instance, table name "Table" or column name "column" are at the wrong level of abstraction. The corresponding code smells in case of cleaning code are "N1: Choose Descriptive Names", "N2: Choose Names at the Appropriate Level of Abstraction", "N4: Unambiguous Names", "N7: Names Should Describe Side-Effects". (Robert C. Martin, Clean Code) |
| Smell "Meaningless name": Sharma, T., Fragkoulis, M., Rizou, S., Bruntink, M. and Spinellis, D.: Smelly relations: measuring and understanding database schema quality. In: Proceedings of the 40th International Conference on Software Engineering: Software Engineering in Practice, pp. 55-64. ACM, (2018). |
| https://www.sqlstyle.guide/ |