mirror of
https://github.com/jbranchaud/til
synced 2026-01-16 13:38:02 +00:00
Add Shorthand Absolute Value Operator as a postgres til
This commit is contained in:
@@ -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).
|
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 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)
|
- [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)
|
- [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)
|
- [Show All Versions Of An Operator](postgres/show-all-versions-of-an-operator.md)
|
||||||
- [Sleeping](postgres/sleeping.md)
|
- [Sleeping](postgres/sleeping.md)
|
||||||
- [Special Math Operators](postgres/special-math-operators.md)
|
- [Special Math Operators](postgres/special-math-operators.md)
|
||||||
|
|||||||
24
postgres/shorthand-absolute-value-operator.md
Normal file
24
postgres/shorthand-absolute-value-operator.md
Normal 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)
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user