Query goal: | Find derived tables that use newer join syntax where join conditions are written in the WHERE clause but do not use USING synatx. |
Query type: | Problem detection (Each row in the result could represent a flaw in the design) |
Query reliability: | Low (Many false-positive results) |
Query license: | MIT License |
Data source: | INFORMATION_SCHEMA+system catalog |
SQL query: | Click on query to copy it
WITH views AS (SELECT views.table_schema, views.table_name, 'VIEW' AS type, views.view_definition FROM information_schema.views WHERE table_schema NOT IN (SELECT schema_name FROM INFORMATION_SCHEMA.schemata WHERE schema_name<>'public' AND schema_owner='postgres' AND schema_name IS NOT NULL) UNION SELECT schemaname, matviewname, 'MATERIALIZED VIEW' AS type, definition FROM pg_catalog.pg_matviews), views_processed AS (SELECT table_schema, table_name, type, view_definition, regexp_replace(view_definition,'[\r\n]','<br>','g') AS view_definition_changed FROM views) SELECT table_schema, table_name, type, view_definition_changed AS view_definition FROM views_processed WHERE view_definition~*'JOIN' AND view_definition!~*'USING[[:space:]]*[(]' ORDER BY table_schema, table_name; |
Category name | Category description |
---|---|
Comfortability of database evolution | Queries of this category provide information about the means that influence database evolution. |
Derived tables | Queries of this category provide information about the derived tables (views, materialized views), which are used to implement virtual data layer. |
Syntactics | Queries of this category provide information about syntactic mistakes. |
Reference |
---|
https://www.neilwithdata.com/join-using |