In PostgreSQL, we can use the RETURNING clause to return data that was modified during an UPDATE, INSERT, or DELETE operation. This allows us to see the data that was modified without having to perform a separate query to retrieve that data.
PostgreSQL
PostgreSQL DATE_BIN() Function Explained
In PostgreSQL, the DATE_BIN() function enables us to “bin” a timestamp into a given interval aligned with a specific origin. In other words, we can use this function to map (or force) a timestamp to the nearest specified interval.
This can be handy when we want to truncate a timestamp to a given interval, for example a 10 minute interval. We can specify the interval (e.g. 10 minutes, 15 minutes, 30 minutes, etc), and we can specify the starting point for the interval. Therefore, we can have the interval starting at any odd time we want (it doesn’t need to start on the hour or anything like that).
7 Ways to Insert Multiple Rows in SQL
We can use the SQL INSERT statement to insert a row into a table. We can also use it to insert more than one row.
Below are seven ways to insert multiple rows into a table in SQL. Most of these examples should work in the major RDBMSs, with the possible exception of Oracle. But no worries, I’ve included an example just for Oracle.
Add Minutes to a Time Value in PostgreSQL
In PostgreSQL, we can use the + operator to add one or more minutes to a time value.
By “time” value, this could be an actual time value, a timestamp, or an interval. We can also add minutes to a date value or a date and time combination.
Subtract Seconds from a Time Value in PostgreSQL
In PostgreSQL, we can use the - operator to subtract one or more seconds from a time value.
By “time” value, this could be an actual time value, a timestamp, or an interval. We can also subtract seconds from a date value or a date and time combination.
Add Seconds to a Time Value in PostgreSQL
In PostgreSQL, we can use the + operator to add one or more seconds to a time value.
By “time” value, this could be an actual time value, a timestamp, or an interval. We can also add seconds to a date value or a date and time combination.
How to Delete Duplicate Rows that have a Primary Key in SQL
The following examples use SQL to delete duplicate rows that have a primary key or unique identifier column.
Specifically, the examples delete all duplicates except one. So for example, in the case of three identical rows, it deletes two of them and keeps one.
2 Ways to Check if a Table has a Generated Column in PostgreSQL
PostgreSQL has supported generated columns since version 12. Generated columns can be created easily with the CREATE TABLE and ALTER TABLE statements.
We can check whether a table contains a generated column or not with the following methods.