![]() ![]() ![]() For the purpose of simplicity, we’re going to use the default yugabyte user for the operations below. In order to create a test setup, I simply installed YugabyteDB on my laptop, created a database example, and loaded the Northwind dataset – all of which only took a few minutes to do. While this post does not explicitly discuss the challenges posed by the example above, the SQL functions below handle these cases correctly and do so by incorporating some of the important and well-known techniques necessary to prevent SQL injection attacks. create table "Some Exotically Named Table"( An instance of a table and a column with an exotic name is shown below. Also, note that the programmatic generation of SQL queries using catalog tables needs to handle exotic names properly. The examples in this blog post, which are essentially dynamic SQL queries on the system catalog tables, must be done with superuser privileges. We will create an example database, import two popular SQL datasets – Northwind and SportsDB, and run through the above scenarios on these example databases. Aggregate row count across all tables in the database.Aggregate row counts per schema of the database.Row counts broken down per table in the schema.This blog post outlines how to get the following row counts of tables in a database: While there are a number of use cases for this, my scenario was to get the per-table row counts of all tables in PostgreSQL and YugabyteDB as a first sanity check after migrating an application with the pre-existing data from PostgreSQL to YugabyteDB. Getting total row counts of data in tables across various dimensions (per-table, per-schema, and in a given database) is a useful technique to have in one’s tool belt of SQL tricks. ![]()
0 Comments
Leave a Reply. |