Below is a full list of date/time functions available in PostgreSQL.
Continue readingTag: functions
PostgreSQL Math Functions
Below is a full list of mathematical functions available in PostgreSQL.
These are arranged into the following four categories:
- Mathematical Functions
- Random Functions
- Trigonometric Functions
- Hyperbolic Functions
SQL Server IF vs IIF(): What’s the Difference?
Students learning a new programming language will often start their first lesson with an IF
statement, where their statement will return a value only if the expression is true.
They might then progress to an IF... ELSE
statement, where they can determine another value to return if the expression is false. So therefore, return one value if the expression is true, and another value if it’s false.
SQL Server certainly includes the IF... ELSE
statement in its T-SQL toolbox.
SQL Server also includes the IIF()
function, which does a similar thing, but with a more concise syntax.
But there are some subtle differences.
Continue readingHow IIF() Works in SQL Server
In SQL Server, the IIF()
function (not to be confused with the IF
statement) is a conditional function that returns the second or third argument based on the evaluation of the first argument.
It’s a shorthand way for writing a CASE
expression. It’s logically equivalent to CASE WHEN X THEN Y ELSE Z END
assuming IIF(X, Y, Z)
.
IIF()
is an abbreviation for Immediate IF.
Calculate the Age in Years in PostgreSQL
Postgres has the age()
function that returns the age in years, months, and days based on two dates.
This works fine unless you only want to return the age in years.
For example, you simply want to return a person’s age based on their birthday. You want something like 32 instead of 32 years 4 mons 67 days, which is what age()
is likely to return.
Fortunately there’s an easy way to do this in PostgreSQL.
Continue readingHow AT TIME ZONE Works in PostgreSQL
In PostgreSQL, you can use the AT TIME ZONE
clause to convert a timestamp to another timezone.
How make_interval() Works in PostgreSQL
In PostgreSQL, the make_interval()
function creates an interval from years, months, weeks, days, hours, minutes and seconds fields.
You provide the years, months, weeks, days, hours, minutes and/or seconds fields, and it will return an interval in the interval data type.
Continue readingHow make_timestamptz() Works in PostgreSQL
In PostgreSQL, the make_timestamptz()
function allows you to create a timestamp with time zone from its year, month, day, hour, minute and seconds fields, as well as an optional timezone field.
How make_date() Works in PostgreSQL
In PostgreSQL, the make_date()
function allows you to create a date from its separate year, month and day fields.
Each date part is provided as an integer, and the result is returned as a date.
Continue readingHow make_time() Works in PostgreSQL
In PostgreSQL, the make_time()
function allows you to create a time from its hour, minute and seconds fields.