| Goal | This query identifies PL/pgSQL and SQL routines with no SQL-standard bodies that use the non-standard LIMIT clause for row limitation. It flags these routines because the official, cross-platform SQL standard specifies FETCH FIRST n ROWS ONLY for this purpose. Adhering to the standard improves code portability and maintainability. To ensure relevance, the query intelligently excludes routines that are part of installed extensions, focusing only on user-defined code. |
| Notes | To ensure accuracy and relevance, the query incorporates several key considerations. It relies on the pg_proc.prokind column, making it compatible with PostgreSQL 11 and newer. For unique identification of overloaded routines, the output includes not just the schema and routine name, but also its parameters. To improve readability in web-based interfaces, newline characters in the routine's body are replaced with tags. Crucially, the query intelligently excludes two types of routines:
|
| Type | Problem detection (Each row in the result could represent a flaw in the design) |
| Reliability | Medium (Medium number of false-positive results) |
| License | MIT License |
| Fixing Suggestion | Use FETCH FIRST n ROWS syntax instead of LIMIT. |
| Data Source | INFORMATION_SCHEMA+system catalog |
| SQL Query |
|
This query belongs to the following collections:
| Name | Description |
|---|---|
| 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 . |
This query is classified under the following categories:
| Name | Description |
|---|---|
| Conformance to SQL standard | Queries of this category provide information about the use of constructs that conform to the SQL standard |
| Syntactics | Queries of this category provide information about syntactic mistakes. |
| User-defined routines | Queries of this category provide information about the user-defined routines |
Further reading and related materials:
| Reference |
|---|
| https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-fetch/ |