| Goal | This query identifies user-defined database objects whose names (identifiers) match SQL keywords that are completely unreserved in PostgreSQL. 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
Review each flagged identifier and consider whether a more descriptive, domain-specific name is possible:
Selecting specific, non-keyword identifiers improves code clarity and protects the schema against future cross-DBMS migration issues.
- Add domain context: Replace generic keywords with qualified names that clearly reflect the object's business purpose (for example, rename type to product_type, date to registration_date, status to order_status, or comment to review_comment).
- Refactor safely: Rename the objects using the appropriate DDL commands (e.g., ALTER TABLE ... RENAME, ALTER TABLE ... RENAME COLUMN), and update all dependent views, routines, and application queries.
Selecting specific, non-keyword identifiers improves code clarity and protects the schema against future cross-DBMS migration issues.
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/ |