1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-04 23:58:01 +00:00

Add Shorthand Absolute Value Operator as a postgres til

This commit is contained in:
jbranchaud
2020-07-14 19:31:05 -05:00
parent 6691890faa
commit f35e334506
2 changed files with 26 additions and 1 deletions

View File

@@ -9,7 +9,7 @@ and pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
_936 TILs and counting..._
_937 TILs and counting..._
---
@@ -512,6 +512,7 @@ _936 TILs and counting..._
- [Set Inclusion With hstore](postgres/set-inclusion-with-hstore.md)
- [Set A Seed For The Random Number Generator](postgres/set-a-seed-for-the-random-number-generator.md)
- [Sets With The Values Command](postgres/sets-with-the-values-command.md)
- [Shorthand Absolute Value Operator](postgres/shorthand-absolute-value-operator.md)
- [Show All Versions Of An Operator](postgres/show-all-versions-of-an-operator.md)
- [Sleeping](postgres/sleeping.md)
- [Special Math Operators](postgres/special-math-operators.md)

View File

@@ -0,0 +1,24 @@
# Shorthand Absolute Value Operator
Postgres offers many [math
functions](https://www.postgresql.org/docs/8.0/functions-math.html) including
`abs` for computing the absolute value of a number.
```sql
> select abs(-1);
abs
-----
1
(1 row)
```
There is also an absolute value _operator_ -- the `@` symbol. This can be used
to do the same thing.
```sql
> select @ -1;
?column?
----------
1
(1 row)
```