Company
Date Published
Author
Karthik Ranganathan
Word count
1300
Language
English
Hacker News points
None

Summary

To get the total row counts of data in tables across various dimensions (per-table, per-schema, and in a given database), one can use SQL techniques that are similar for PostgreSQL and YugabyteDB. A user-defined function (UDF) named `count_rows_of_table` can be created to count the number of rows in a single table. By querying the `information_schema.tables` table and using this UDF, row counts can be obtained per-table, per-schema, and across all tables in a database. Additionally, aggregate row counts can be calculated by grouping the results by schema or by summing up the individual row counts. These techniques are useful for sanity-checking data after migrating an application from PostgreSQL to YugabyteDB and can help prevent SQL injection attacks when generating dynamic SQL queries.