I have a query in mysql, trying to convert to Postgre, I could not find 'information_schema.STATISTICS' equivalent in Postgre. Is there any way to achieve in Postgre.
Full Query:
SELECT t.TABLE_NAME as TName
FROM information_schema.TABLES t
JOIN information_schema.STATISTICS s on
s.TABLE_CATALOG = t.TABLE_CATALOG
AND s.TABLE_SCHEMA = t.TABLE_SCHEMA
AND s.TABLE_NAME = t.TABLE_NAME
AND s.INDEX_NAME = 'PRIMARY'
AND s.COLUMN_NAME = 'PK'
AND s.SEQ_IN_INDEX = 1
JOIN information_schema.COLUMNS c on
c.TABLE_CATALOG = t.TABLE_CATALOG
AND c.TABLE_SCHEMA = t.TABLE_SCHEMA
AND c.TABLE_NAME = t.TABLE_NAME
AND c.COLUMN_NAME = 'VERSION'
WHERE 1=1
AND t.TABLE_NAME LIKE '%\\_%'
AND t.TABLE_SCHEMA LIKE '%\\_%'
AND BINARY(t.TABLE_NAME) != LOWER(t.TABLE_NAME)```
In this query, we are trying to get tables which are having PRIMARY as index_name(that is the one index mysql creates automatically), and index_column is PK.
And also the table should have a column called 'VERSION'.
There isn't a direct equivalent to MySQL's
information_schema.STATISTICStable inPOSTGRESQLso have to try with with PostgreSQL's system catalogspg_class, pg_attribute, and pg_indexto find tables with a primary key named 'PK' and a column named 'VERSION'.