PostgreSQL – How to view the Size of a Table

To get the size of a specific table in PostgreSQL, you can use the pg_total_relation_size function. This function returns the total size of a table in bytes, including the main data file, indexes, and associated objects. Below is the syntax: SELECT pg_size_pretty(pg_total_relation_size(‘your_table_name’)); where ‘your_table_name’ with the name of the table you want to get the…

PostgreSQL – How to get the List of All Schemas

To retrieve a list of all schemas in a PostgreSQL database, you can use the following SQL query: SELECT schema_name FROM information_schema.schemata; This query queries the information_schema.schemata view, which contains information about all the schemas in the current database. When you execute this query, it will return a list of schema names present in the…

PostgreSQL – How to Generate and Insert uuid

The gen_random_uuid() function is used to generate a random UUID (Universally Unique Identifier) in PostgreSQL database. UUIDs are 128-bit identifiers that are often used as unique keys in database tables or for generating random values. Here’s how you can use gen_random_uuid() to generate a random UUID in PostgreSQL: SELECT gen_random_uuid(); When you execute above SQL…

PostgreSQL – XMLAGG Function

The XMLAGG function in PostgreSQL is used to aggregate multiple XML elements into a single XML value. It is often used in combination with other functions like XMLELEMENT to construct XML documents or fragments. XMLAGG takes a set of XML values and concatenates them together. Here’s the basic syntax of the XMLAGG function: XMLAGG(expression ORDER…