The list of all the queries

Generated stored base table columns duplicates another column in the table

Query goal: Find generated stored columns in PostgreSQL base tables that duplicate other columns in the table.
Query type: Problem detection (Each row in the result could represent a flaw in the design)
Query reliability: High (Few or no false-positive results)
Query license: MIT License
Fixing suggestion: If you need two columns with the same content but with different names, then use instead a view on top of the table.
Data source: INFORMATION_SCHEMA only
SQL query: Click on query to copy it

SELECT table_schema, table_name, column_name, generation_expression
FROM INFORMATION_SCHEMA.columns AS c
WHERE (table_schema, table_name) IN (SELECT table_schema, table_name
FROM INFORMATION_SCHEMA.tables WHERE table_type='BASE TABLE') 
AND 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) 
AND is_generated='ALWAYS'
AND EXISTS (SELECT *
FROM INFORMATION_SCHEMA.columns AS c2
WHERE c.table_name=c2.table_name
AND c.generation_expression=c2.column_name)
ORDER BY table_schema, table_name, ordinal_position;

Collections where the query belongs to

Collection nameCollection description
Find problems automaticallyQueries, 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 where the query belongs to

Category nameCategory description
Duplication of implementation elementsQueries of this catergory provide information about the duplication of the database objects.
Generated columnsQueries of this category provide information about generated stored base table columns.

The list of all the queries