https://www.postgresqltutorial.com/postgresql-delete-join/
PostgreSQL DELETE JOIN - How to Emulate it Correctly
Summary: in this tutorial, you will learn how to use the PostgreSQL DELETE statement to emulate delete join operations. Introduction to PostgreSQL DELETE statement with USING clause PostgreSQL doesn’t support the DELETE JOIN statement. However, it does s
www.postgresqltutorial.com
postgresql에선 delete from 절에서 join 사용이 불가능한듯 하다.
delete from (
users
join projects as p1
on users.project_id = p1.id
)
where (
users.id = $1
and p1.type = $2
and p1.id = $3
)
-- delete from '(' 에서 syntax error 발생.
-- 위 쿼리문은 예제일 뿐이니 이상해도 넘어가자.
그래서 아래와 같이 using을 활용해주어야 한다.
delete from users
using projects
where (
users.project_id = projects.id
and users.id = $1
and projects.type = $2
)
-- 역시 자세한 부분은 넘어가자.