8
15

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 5 years have passed since last update.

PostgreSQL コマンド Mac

Last updated at Posted at 2018-10-03

■起動/終了

postgres -D /usr/local/var/postgres

以降のコマンドを打つ際は、ターミナルを別に開いて実行してください。

■データベースの一覧表示

psql -l

テーブル一覧

\dt;

■データベースに接続

psql -U ユーザー名 データベース名

■接続

psql テーブル名;

■DB作成

create database データベース名;

■DBの切り替え

\c dbname

■テーブル一覧表示

\z

■テーブル作成

CREATE TABLE tablename (
 id serial PRIMARY KEY,
 aaa text,
 bbb text
 );

■テーブル削除

DROP TABLE tablename

■テーブル削除

insert into tablename (aaa,bbb) values('AAA','BBB');
『"』で囲うとエラーになります。

■切断

\q
8
15
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
8
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?