Files
gemini-grc/misc/sql/cleanup_duplicate_snapshots.sql
antanst 8bbe6efabc Improve error handling and add duplicate snapshot cleanup
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-18 11:56:26 +03:00

20 lines
469 B
SQL

WITH snapshot_rankings AS (
SELECT
id,
url,
ROW_NUMBER() OVER (
PARTITION BY url
ORDER BY
CASE WHEN (gemtext IS NOT NULL AND gemtext != '') OR data IS NOT NULL
THEN 0 ELSE 1 END,
timestamp DESC
) as rn
FROM snapshots
)
DELETE FROM snapshots
WHERE id IN (
SELECT id
FROM snapshot_rankings
WHERE rn > 1
);