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 – How to List all Tables

To list all the tables in a PostgreSQL database, you can query the information_schema database which contains metadata about all the tables and other objects in the database. Below is the SQL query you can use to show all the tables: SELECT table_name FROM information_schema.tables WHERE table_schema = ‘public’; This query will retrieve the names…

PostgreSQL – How to Convert String to Date

You can convert a string to a date using the TO_DATE function in PostgreSQL. This function allows you to specify the input string, the format of the string, and it will return a date accordingly. The general syntax of the TO_DATE function is as follows: TO_DATE(input_string, format_string) Here’s an example of using SELECT TO_DATE(‘2023-08-31’, ‘YYYY-MM-DD’);…