행을 넣고, 고르고, 고치고, 지웁니다.
insert는 행을 추가한다. 적지 않은 열은 기본값이나 빈 값이 된다. id와 created_at은 생략해도 된다.
insert into posts (title, body)
values ('첫 글', '안녕하세요');
select는 행을 읽는다. where가 없으면 모든 행이다. where가 있으면 그 조건에 맞는 행만 나온다. Supabase의 .select('id, title')는 이 문장과 같다.
select id, title
from posts
where title like '첫%'
order by created_at desc;
like '첫%'는 ‘첫’으로 시작하는 제목이다. %는 그 뒤의 임의 글자다. order by created_at desc는 최근 글이 위로 온다.
where 없이 update나 delete를 실행하면 표의 모든 행이 바뀐다. 항상 기본 키로 한 행을 집는다.
update posts
set title = '고친 제목'
where id = 1;
delete from posts
where id = 1;
Supabase의 .insert({ title })와 .from('posts').select()는 이 insert, select를 API로 보낸 것이다. 키가 publishable이어도, 정책이 거절하면 이 SQL은 실행되지 않는다.