In PostgreSQL, we can use the lower()
function to convert uppercase characters to their lowercase equivalent, according to the rules of the database’s locale.
Tag: psql
Get the First Day of the Month in PostgreSQL
We can use the following method in PostgreSQL to return the first day of a given month.
This could be the first day of the current month, or the first day of the month based on a date that we specify.
Getting the first day of the month allows us to perform further calculations on the resulting date, like adding a certain number of days to the start of the month, etc.
Continue readingAdd Hours to a Time Value in PostgreSQL
In PostgreSQL, we can use the +
operator to add one or more hours to a time value.
By “time” value, this could be an actual time
value, a timestamp
, or an interval
. We can also add hours to a date
value or a date
and time
combination.
INITCAP() – Convert to Initial Caps in PostgreSQL
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.
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.