0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Heroku Postgresを触る(・接続・取得・追加・削除・更新・終了)

Last updated at Posted at 2021-04-26

データベースに接続

$ heroku pg:psql

テーブルの一覧表示

> \d
 Schema |    Name     | Type  |     Owner      
--------+-------------+-------+----------------
 public |   querys    | table |     *****

以下、querysというテーブルがある前提で記述する

データの取得

> SELECT * FROM querys;
 query  | qty |
--------+-----------
 qiita  |  2  |
 heroku |  1  |

querysというテーブルに、queryとqtyというカラムがあり、2つのレコードがある

データの削除

> DELETE FROM querys WHERE query='qiita';
DELETE 1

複数レコードの削除

> DELETE FROM querys WHERE query='qiita' OR query='heroku';
DELETE 2

データの追加

> INSERT INTO querys (query, qty) VALUES ('qiita', 2);
INSERT 0 1

データの更新

> UPDATE querys SET query='github' WHERE query='qiita';
UPDATE 1

複数カラムの更新

> UPDATE querys SET query='github' qty=3 WHERE query='qiita';
UPDATE 1

接続の解除

> \q
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?