Tag: sql Tag: postgresql

練習、テストに便利な事のメモ

valuesによりテーブルを作らないデータでのテスト・・・

select * from (values(1,2),(2,3),(3,4),(4,6),(10,20),(11,30)) as t (a,b);
 a  | b  
----+----
  1 |  2
  2 |  3
  3 |  4
  4 |  6
 10 | 20
 11 | 30
(6 rows)
 
select column2,column1 from (select * from (values(1,2),(2,3),(3,4),(4,6),(10,20),(11,30)) as t) as u;                                                       
 column2 | column1 
---------+---------
       2 |       1
       3 |       2
       4 |       3
       6 |       4
      20 |      10
      30 |      11
(6 rows)

参考: https://www.postgresql.jp/document/9.4/html/sql-values.html