工作と競馬2

電子工作、プログラミング、木工といった工作の記録記事、競馬に関する考察記事を掲載するブログ

PostgreSQLクエリコマンド覚書

コメント

-- ハイフンを2つ

データベース一覧

select * from pg_database;

テーブル名一覧

select relname as TABLE_NAME from pg_stat_user_tables;

テーブル内のカラム一覧

select 
    *
from
    information_schema.columns 
where 
    table_catalog='データベース名' 
    and 
    table_name='テーブル名' 
order by ordinal_position;

レコードをクエリ

select
    カラム名, ...
from
    テーブル名
  • 条件
where カラム名 比較演算子 値

比較演算子: =, >=, <=など
  • timestamp型の場合

文字列をキャストする

where timestamp型のカラム名 >= cast('2020-01-20 14:00:00' as timestamp)
  • 件数制限
limit 30;