The +
operator allows us to add one or more days to a given date in PostgreSQL. We have a few options when it comes to specifying the actual number of days.
Tag: psql
Subtract Days from a Date in PostgreSQL
We can subtract one or more days from a date in PostgreSQL with the -
operator.
PostgreSQL DATEADD() Equivalent
Updated 20 April 2024 to include the date_add()
function.
SQL Server has its DATEADD()
function that adds an interval to a date value. MySQL’s DATE_ADD()
and ADDDATE()
for does the same thing, as does MariaDB’s DATE_ADD()
and ADDDATE()
. SQLite has a DATE()
function that also provides the option of adding an interval to a given date.
Prior to version 16, PostgreSQL didn’t have a DATEADD()
or equivalent function. But with PostgreSQL 16 came with the introduction of the date_add()
function, which allows us to add an interval to a timestamp with time zone.
We can also add and subtract values from dates with date/time operators such as +
and -
.
PostgreSQL VALUES Command Explained
In PostgreSQL, the VALUES
command returns a set of one or more rows as a table. It’s a table value constructor that can be used as part of a larger command, or as a standalone SQL statement.
How to Show the Current Setting for Null Output in PostgreSQL (psql)
When using psql, null values are returned as an empty string by default.
This can easily be changed with the \pset
command, so it could be a value other than the default empty string.
If you’re not sure what your current value is, you can use the show \pset null
command to show the current value.
PostgreSQL DESCRIBE TABLE Equivalent
Some DBMSs such as Oracle, MySQL, and MariaDB have a DESCRIBE
command that returns information about tables and views. It goes DESCRIBE table
where table is the name of the table or view, and it can also be followed by a column name if you only want information about a specific column.
PostgreSQL doesn’t have a DESCRIBE TABLE
command as such, but there are alternatives.
3 Ways to Check a Column’s Data Type in PostgreSQL
Here are three ways to get the data type of a given column in MariaDB.
Continue readingHow to Change the Table Border Style in the psql Query Results
When using psql
to run queries against PostgreSQL, we can use the \pset border
and \pset linestyle
commands to change the border of the table that displays our results.
How to Show Null Values When Running Queries in psql (PostgreSQL)
By default, null values are returned as an empty string in psql. But this can easily be changed.
One reason you might want to change this is to avoid null values being confused with actual empty strings.
You can change this with the \pset null 'value'
command.
How to Check your psql Client Version
Here’s how to find out what version of psql you’re using.
Continue reading