This code below works with SELECT statement:
WITH
smaller_uuid AS (
SELECT
id, uuid, email, first_name, last_name, display_name
FROM stack_users_production.users AS user1
WHERE EXISTS (
SELECT
id, uuid, email
FROM
stack_users_production.users AS user2
WHERE
user1.id = user2.id AND
user1.email = user2.email AND
user1.uuid < user2.uuid
)
)
SELECT
id, uuid, email, first_name, last_name, display_name
FROM
stack_users_production.users
WHERE
uuid IN (SELECT uuid FROM smaller_uuid);
But this code below does not work with DELETE statement:
WITH
smaller_uuid AS (
SELECT
id, uuid, email, first_name, last_name, display_name
FROM stack_users_production.users AS user1
WHERE EXISTS (
SELECT
id, uuid, email
FROM
stack_users_production.users AS user2
WHERE
user1.id = user2.id AND
user1.email = user2.email AND
user1.uuid < user2.uuid
)
)
DELETE FROM
stack_users_production.users
WHERE
uuid IN (SELECT uuid FROM smaller_uuid);
It says syntax error:
psql:snippets.pgsql:113: ERROR: syntax error at or near "DELETE" LINE 18: DELETE FROM
I am using PostgreSQL 9.6.3, and is connected to AWS Redshift when executing this query.