Skip to content

Instantly share code, notes, and snippets.

View zacharyarnaise's full-sized avatar
🐙

Zachary Arnaise zacharyarnaise

🐙
  • /dev/null, France
  • 11:14 (UTC +01:00)
View GitHub Profile
@zacharyarnaise
zacharyarnaise / django_rq_cs.py
Last active July 20, 2024 15:57
Django RQ cheatsheet
import django_rq
import rq
import rq.registry
from conf import settings
conn = django_rq.get_connection()
# Get all workers
@zacharyarnaise
zacharyarnaise / psql_duplicate_row.sql
Created November 28, 2023 16:58
PostgreSQL: duplicate a row multiple times
CREATE TEMPORARY TABLE temporary_table AS SELECT * FROM <my_table> WHERE <condition>;
-- Remove any columns that will cause a constraint error when re-inserting the row
ALTER TABLE temporary_table DROP COLUMN id;
-- Re-insert 100 copies of the row with a new UUID
INSERT INTO <my_table> SELECT uuid_generate_v4() AS id, temporary_table.* FROM temporary_table CROSS JOIN GENERATE_SERIES(1,100);
@zacharyarnaise
zacharyarnaise / psql_index_stats.sql
Created November 8, 2023 15:00
PostgreSQL: index stats
SELECT
psui.relname AS table_name,
pg_size_pretty(pg_relation_size(psui.relid)) AS table_size,
psui.indexrelname AS index_name,
psui.idx_scan AS index_scans_count,
pg_size_pretty(pg_relation_size(psui.indexrelid)) AS index_size,
psut.idx_scan AS table_idx_scans_count,
psut.seq_scan AS table_seq_scans_count,
psut.seq_scan + psut.idx_scan AS table_scans_total
FROM pg_stat_user_indexes AS psui