In PostgreSQL, we can use the -
operator to subtract one or more months from a date.
Category: PostgreSQL
Return the Unix Timestamp in PostgreSQL
In PostgreSQL, we can use the extract()
function along with the epoch
argument to return the Unix timestamp.
We can return the Unix timestamp based on the current date/time, or we can get it based on another specified date/time.
Continue readingFix “INSERT has more expressions than target columns” in PostgreSQL
If you encounter an error that reads “INSERT has more expressions than target columns” when trying to insert data in Postgres, it’s because you’re trying to insert data into more columns than the table actually contains.
Continue readingSubtract Minutes from a Time Value in PostgreSQL
In PostgreSQL, we can use the -
operator to subtract one or more minutes from a time value.
By “time” value, this could be an actual time
value, a timestamp
, or an interval
. We can also subtract minutes from a date
value or a date
and time
combination.
Get the Number of Days in a Month in PostgreSQL
Here’s an example of using PostgreSQL to return the number of days in a month, based on a given date.
Continue readingUPPER() – Convert to Uppercase in PostgreSQL
In PostgreSQL, we can use the upper()
function to convert lowercase characters to their uppercase equivalent, according to the rules of the database’s locale.
LOWER() – Convert to Lowercase in PostgreSQL
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.
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.