WITH dupes AS (
    SELECT
        uid,
        link,
        Row_number() over(
            PARTITION by link
            ORDER BY
                link
        ) AS RowNumber
    FROM
        post
)
DELETE FROM
    post
WHERE
    uid IN (
        SELECT
            uid
        FROM
            dupes
        WHERE
            RowNumber > 1
    );

ALTER TABLE
    post
ADD
    UNIQUE (link);
