Help us understand the problem. What is going on with this article?

PostgreSQLコマンド 備忘録

More than 1 year has passed since last update.

はじめに

最近PostgreSQLを使っていてコマンドを中々覚えていないので、メモとしてこちらに残します。
新しい知識が入り次第更新する予定です。

接続

psql -U username -h hostname databasename

データベース一覧

# \l

テーブルの一覧

# \dt

テーブルのデータ一覧

# select * from テーブル名;

レコードの条件検索

where句を使う!
例えばusersテーブルのcompany_idが33のidを検索したいとき

# select * from users where company_id = 33;

AND演算子

複数の条件を指定したい時に使う。AND演算子の場合、全ての条件が正のとき、式も正になる。
例えば、usersテーブルのcompany_idが33で、かつaccess_idが3のidを検索したいとき

# select * from users where company_id = 33 AND access_id = 3;

レコードのデータを更新

データの更新には、update構文を使う。
例えばusersテーブルのuser_idが20でcompany_idを2に更新したい時は

# update users set company_id = 2 where id = 20;

レコードを全部削除する

# delete from テーブル名;

終了

# \q

参考

PostgreSQLの基本的なコマンド

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away