SELECT
Expressions can get very complex.
You may want to test out a computation without getting any data from any tables.
You can do this by removing the FROM
clause and using just SELECT
with an expression.
SELECT (1.0 + sqrt(5.0)) / 2.0 AS golden_ratio;
golden_ratio NUMERIC |
---|
1.6180339887498950 |
This uses the sqrt()
function, which computes a square root.
Notice the new data type: NUMERIC
!
This is a number with a fractional part, or a real number which can be non-integer.
Here is an example with multiple expressions:
SELECT
sin(pi() / 2),
now(),
repeat('(╯°□°)╯︵ ┻━┻ ', 2);
sin FLOAT | now TIMESTAMPTZ | repeat TEXT |
---|---|---|
1 | 2023-07-17 00:02:21.571987+00 | (╯°□°)╯︵ ┻━┻ (╯°□°)╯︵ ┻━┻ |
There are several new functions here which should be intuitive. Again, don't make an effort to memorize these. Utilize Google and the Postgres documentation when needed.
There is another new data type too.
The now()
function returns a type TIMESTAMPTZ
.
This represents a date and a time.
We'll use this in future lessons.