In Postgres, you can use the to_char()
function to return the century, based on a given date.
To do this, use CC
as the second argument. This returns the two-digit century based on the date provided.
In Postgres, you can use the to_char()
function to return the century, based on a given date.
To do this, use CC
as the second argument. This returns the two-digit century based on the date provided.
In PostgreSQL, you can use the to_char()
function to output numbers in a given format. This includes appending the number with the ordinal indicator.
For example 1, 2, 3 becomes 1st, 2nd, 3rd.
Continue readingThe PostgreSQL to_char()
function provides us with the option of adding the ordinal number suffix to the result.
This means we can add the ordinal indicator when formatting dates.
For example, instead of outputting 10 Feb we could output 10th Feb.
Continue readingThe easiest way to install PostgreSQL on a Mac is by installing Postgres.app. Postgres.app is a full-featured PostgreSQL installation packaged as a standard Mac application.
You simply download it and drag it to your Applications folder, just like with any other application.
Continue readingWhen working with Postgres, you can use the to_char()
function to output numbers in a given format.
The way it works is that you provide two arguments. The first argument is the number to be formatted. The second argument determines how it is formatted.
The return value is text.
Depending on your requirements, you might prefer to convert the number to the appropriate data type, for example using the cast()
function.
Examples of both methods are below.
Continue readingIn PostgreSQL, you can use the to_char()
to output a number in a certain format, including with a plus or minus sign to indicate whether it’s a positive or negative number.
To do this, use one of S
, MI
, PL
, or SG
in your format string.
Another option is to use PR
in order to enclose any negative values in angle brackets.
In PostgreSQL, you can get the day name from a date by using the to_char()
function. This function returns a string based on the timestamp and the template pattern you provide as arguments..
In PostgreSQL, you can use the to_char()
function to get the short month name from a date.
By “short month name” I mean the abbreviated month name, for example Jan, Feb, Mar, etc.
The to_char()
function accepts two parameters; the date and the format string with which to format that date.
When creating a table in SQLite, you have the option of adding constraints to each column.
One such constraint is the DEFAULT
constraint.
The DEFAULT
constraint allows you to specify a value to be used in the event no value is supplied for that column when a new row is inserted.
If you don’t use a DEFAULT
clause, then the default value for a column is NULL
.
You can add a generated column to an existing table in SQLite by using the ALTER TABLE
statement.
SQLite’s implementation of the ALTER TABLE
statement is very limited, but it does allow you to add a column – including generated columns.
Generated columns (also known as “computed columns”) are columns that get their value from an expression that computes values from other columns.
Continue reading