1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
CREATE TABLE test (name TEXT, value FLOAT);
INSERT INTO test VALUES ('a',random()),('b',random()),('c',random());
SELECT t.* FROM test t JOIN (VALUES ('b',1),('c',2),('a',3)) o ON (o.column1=t.name) ORDER BY o.column2;
name | value
------+-------------------
b | 0.313314548693597
c | 0.676097862888128
a | 0.604159130714834
WITH o AS (VALUES ('b',1),('c',2),('a',3)) SELECT t.* FROM test t JOIN o ON (o.column1=t.name) ORDER BY o.column2;
name | value
------+-------------------
b | 0.313314548693597
c | 0.676097862888128
a | 0.604159130714834
EXPLAIN ANALYZE SELECT t.* FROM test t JOIN (VALUES ('b',1),('c',2),('a',3)) o ON (o.column1=t.name) ORDER BY o.column2;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------
Sort (cost=26.54..26.58 rows=17 width=44) (actual time=0.043..0.044 rows=3 loops=1)
Sort Key: "*VALUES*".column2
Sort Method: quicksort Memory: 25kB
-> Hash Join (cost=0.08..26.20 rows=17 width=44) (actual time=0.031..0.032 rows=3 loops=1)
Hash Cond: (t.name = "*VALUES*".column1)
-> Seq Scan on test t (cost=0.00..21.60 rows=1160 width=40) (actual time=0.006..0.006 rows=3 loops=1)
-> Hash (cost=0.04..0.04 rows=3 width=36) (actual time=0.009..0.009 rows=3 loops=1)
-> Values Scan on "*VALUES*" (cost=0.00..0.04 rows=3 width=36) (actual time=0.004..0.006 rows=3 loops=1)
Total runtime: 0.083 ms |
Partager