postgresql
データを入れる
- insert into {table} (**, **, **, **, **) values (*, *, *, *, *)
test=# insert into weather (city, temp_lo, temp_hi, prcp, date)
values ('san fr ancisco', 43, 57, 0.0, '2007-07-10');
テーブル内容を表示
抽出する
結果から重複行を除くように指定
テーブルを結合する
- select * from {table_id}, {table_id_2} where {column} = {column}
test=# select * from weather, cities where city = name;
city | temp_lo | temp_hi | prcp | date | name | location
---------------+---------+---------+------+------------+---------------+-------------
san francisco | 46 | 50 | 0.25 | 2006-07-12 | san francisco | (-194,53.9)
san francisco | 43 | 57 | 0 | 2007-07-10 | san francisco | (-194,53.9)
(2 rows)
選ぶ
更新する
コマンドをviewに登録して楽をする
- create view {viewの名前} select {内容} from {table} where {column}={値};
- select * from {viewの名前}で参照する事が出来る
test=# create view myview as select city, temp_lo, temp_hi, prcp, date, location from weather, cities where city = name;
CREATE VIEW
test=# select * from myview;
city | temp_lo | temp_hi | prcp | date | location
---------------+---------+---------+------+------------+-------------
san francisco | 46 | 50 | 0.25 | 2006-07-12 | (-194,53.9)
san francisco | 41 | 55 | 0 | 2007-07-10 | (-194,53.9)
(2 rows)
|