I moved to PostgreSQL from using MySQL, and [...] I just thought it was a bigger, more complicated database that did 'the same stuff' as MySQL. It took me a while to really realize how great the 'other' features are.Joel Burton - Director of Information Systems Support Center of Washington
Good luck!
Created by Felix Seidel
PostgreSQL is pronounced Post -Gres -Q -L.
If you find 'PostgreSQL' hard to pronounce, call it 'Postgres' instead.
Source: wiki.postgresql.org
avg(salary) filter (where dept_id = 1)It depends
<, >, <=, >=, <> or !=a BETWEEN (symmetric) x AND yexpression IS NULLboolean_expression IS NOT FALSE
> select * from generate_series(1,10) as numbers(a)
where numbers.a between 5 and 3;
a
---
> select * from generate_series(1,10) as numbers(a)
where numbers.a between symmetric 5 and 3;
a
---
3
4
5
age(timestamp, timestamp)OVERLAPS
select age(timestamp '2001-04-10', timestamp '1957-06-13');
result: 43 years 9 mons 27 days
SELECT (DATE '2001-02-16', DATE '2001-12-21') OVERLAPS
(DATE '2001-10-30', DATE '2002-10-30');
Result: true
=, <>, @>, ||array_length(anyarray, int)array_append(anyarray, anyelement)array_remove(anyarray, anyelement)
ARRAY[1.1,2.1,3.1]::int[] = ARRAY[1,2,3] => true
ARRAY[1,4,3] @> ARRAY[3,1] => true
ARRAY[1,2,3] || ARRAY[4,5,6] => {1,2,3,4,5,6}
array_length(array[1,2,3], 1) => 3
array_remove(ARRAY[1,2,3,2], 2) => {1,3}
array_agg()avg()count()every()min()max()sum()
SELECT min(a), max(a), sum(a),
every(a<11), every(a=3),
array_agg(a), avg(a), count(a)
FROM generate_series(1,10) as a;
---
| min | max | sum | every | every |
| 1 | 10 | 55 | true | false |
| array_agg | avg | count |
| {1,2,3,4,5,6,7,8,9,10} | 5.5 | 10 |
EXISTSINNOT INANY || SOMEALL
SELECT array_agg(a)
FROM generate_series(1,4) as a
where a not in(select generate_series(3,10))
{1,2}
SELECT array_agg(a)
FROM generate_series(1,4) as a
where a > any(select generate_series(1,2))
{2,3,4}
<, <=, =, >=, >BETWEENINIS NULL=
for rows that overlap values
for columns with multiple values
for large narturally sortable data
EXPLAIN SELECT * FROM tenk1;
QUERY PLAN
-------------------------------------------------------------
Seq Scan on tenk1 (cost=0.00..458.00 rows=10000 width=244)
(cost=startup-cost..total-cost rows=estimated width=bytes)
EXPLAIN ANALYZE SELECT * FROM tenk1 WHERE ten < 7;
QUERY PLAN
------------------------------------------------------------
Seq Scan on tenk1 (cost=0.00..483.00 rows=7000 width=244)
(actual time=0.016..5.107 rows=7000 loops=1)
Filter: (ten < 7)
Rows Removed by Filter: 3000
Planning time: 0.083 ms
Execution time: 5.905 ms
(actual time=sartup-time..total-time rows=actual loops=1)
LIKEWHERE clauseIN() statementsJOIN statementsEXISTS when checking for existence of rows