MIN function is an aggregate function that allows you to get the minimum of values. Example: Consider the employee table
Continue readingPostgreSQL – MAX Function
MAX function is an aggregate function that allows you to get the maximum of values. Example: Consider the employee table
Continue readingPostgreSQL – AVG (Average) Function
AVG function is an aggregate function that allows you to get the average of values. Example: Consider the employee table
Continue readingPostgreSQL – Adding days to Date
In Postgres, you can query today’s date as below: SELECT current_date; To get tomorrow’s date, simply add 1 day to
Continue readingPostgreSQL – Get Table Size
Use the below query to determine the size of a table in Postgres database: SELECT pg_size_pretty(pg_table_size(‘table_name’)); The below query gives
Continue readingPostgreSQL – Escape single quote
You can escape the single quote character by making it a double single quote as shown below: Example: Insert into
Continue readingPostgreSQL – How to call a function
In postgresql database, functions are called from within a select statement as shown below: SELECT function_name(function_arg1, function_arg2,…); Example: Below is
Continue readingPostgreSQL – Extract date from timestamp
To extract date from timestamp field, you can simply use the date function as shown below; where timestamp_column is the
Continue readingPostgreSQL – Switching between databases
You can connect to a different database from within the psql prompt using below command where databasename is the name
Continue readingPostgreSQL – Get first row within each group
In Postgres database, you can use DISTINCT ON to select one row per group. Consider the below employee table; where
Continue reading