SELECT count(*) FROM information_schema.columns WHERE table_name = 'mytable' AND table_schema = 'jim';
Minimalistic Oracle contains a collection of practical examples from my encounters with Oracle technologies. When relevant, I also write about other technologies, like Linux or PostgreSQL. Many of the posts starts with "how to" since they derive directly from my own personal experience. My goal is to provide simple examples, so that they can be easily adapted to other situations.
Showing posts with label Number of rows. Show all posts
Showing posts with label Number of rows. Show all posts
Monday, November 17, 2025
Find the number of columns in a table in postgreSQL
Wednesday, August 27, 2025
List a table, its partitions and the number of rows it contains
SELECT
s.schemaname,
s.relname AS table_name,
s.n_live_tup,
s.last_analyze,
s.last_autoanalyze
FROM
pg_stat_all_tables s
JOIN
pg_class c ON c.relname = s.relname
LEFT JOIN
pg_inherits i ON i.inhrelid = c.oid OR i.inhparent = c.oid
WHERE
s.schemaname = 'myschema'
AND (
s.relname = 'mytable'
OR c.oid IN (
SELECT inhrelid
FROM pg_inherits
WHERE inhparent = (
SELECT oid FROM pg_class WHERE relname = 'mytable'
)
)
)
ORDER BY
s.n_live_tup DESC,s.last_analyze;
Example output
schemaname | table_name | n_live_tup | last_analyze | last_autoanalyze -----------------+-----------------+------------+-------------------------------+------------------------------ myschema | mytable_2015_02 | 95788115 | 2025-08-06 12:58:22.952592+00 | myschema | mytable_2015_03 | 78505350 | 2025-08-06 12:58:37.147433+00 | myschema | mytable_2015_04 | 71211253 | 2025-08-06 12:58:51.311452+00 | myschema | mytable_2015_01 | 68255510 | 2025-08-06 12:58:08.42708+00 | myschema | mytable_2015_05 | 62075043 | 2025-08-06 12:59:05.434118+00 | myschema | mytable_2015_06 | 60888876 | 2025-08-06 12:59:19.918657+00 | 2025-08-06 11:31:19.551345+00 myschema | mytable_2015_12 | 57485594 | 2025-08-06 13:00:43.112316+00 | 2025-08-27 03:13:11.394606+00 myschema | mytable_2016_01 | 57405307 | 2025-08-06 13:00:55.395113+00 | 2025-08-25 13:35:07.749773+00
Subscribe to:
Comments (Atom)