In PostgreSQL, we can use the initcap()
function to format a string of text to use initial capitals. That is, it converts the first letter of each word to upper case and the rest to lower case.
Tag: psql
2 Ways to Show All Databases in PostgreSQL (psql)
Here are a couple of ways to show a list of databases when using psql
with PostgreSQL.
The first option can be used when we’re already connected to PostgreSQL. The second option can be used when we don’t currently have a connection to Postgres.
Continue readingSubtract Years from a Date in PostgreSQL
In PostgreSQL, we can use the -
operator to subtract one or more years from a date.
Add Years to a Date in PostgreSQL
In PostgreSQL, we can use the +
operator to add one or more years to a date.
PostgreSQL SHOW TABLES Equivalent (psql)
MySQL and MariaDB have a SHOW TABLES
statement, which outputs a list of tables and views in a database. PostgreSQL doesn’t have a SHOW TABLES
statement, but it does have a command that produces a similar result.
In Postgres, you can use the \dt
command to show a list of tables. This is a psql command (psql is the interactive terminal for PostgreSQL).
Add Weeks to a Date in PostgreSQL
In PostgreSQL, we can use the +
operator to add one or more weeks to a date. We have a few options when it comes to specifying the actual number of weeks.
Add Months to a Date in PostgreSQL
In PostgreSQL, we can use the +
operator to add one or more months to a date. There are several options when it comes to specifying the actual number of months.
Add Days to a Date in PostgreSQL
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.
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 -
.