はじめに
- SQLはほぼselectしか打たないし、selectも簡単なleft join、inner join、like、limit、whereしかわからない。
問題
- select以外のSQL全然文法知らないので以下を調べたり実行して確認した
- int4にする方法
- uuidの値を入れる方法
- create table文
- PKの指定方法
解決
- 以下の感じでとりあえずテストデータ作成したりできる
create table hogepiyos(
id uuid NOT NULL,
title varchar(255) NOT NULL,
time int4 NOT NULL,
primary key (id)
)
insert into hogepiyos(
id, title, time
) values
(gen_random_uuid(), 'hoge', 10),
(gen_random_uuid(), 'fuga', 2),
(gen_random_uuid(), 'piyo', 4)
select * from hogepiyos
-- drop table hogepiyos
終わりに
- select以外の、selectもgroup byとか、where in (select column_name from hoges~~)とか、実行計画読むとか今後やっていきたい
