Skip to content

Instantly share code, notes, and snippets.

@ashkangoleh
ashkangoleh / groups.sql
Created November 7, 2023 06:00 — forked from EcZachly/groups.sql
How to write an algorithm to group people in optimized groups based on timezone and track
-- first query all the users
WITH offsets AS (SELECT a.*,
EXTRACT(hour FROM ptn.utc_offset) AS utc_offset
FROM bootcamp.attendees a
JOIN pg_timezone_names ptn ON a.timezone = ptn.name
WHERE a.bootcamp_version = 3
AND a.timezone IS NOT NULL
AND a.content_delivery = 'Live'::text
),
-- then aggregate the users by track and offset, we want matching timezones to fill up first
@ashkangoleh
ashkangoleh / gist:18480b4e7345bf04ed96b81c221e99cd
Created March 17, 2022 07:03
Postgresql table sized depends on schema
For get all of tables size depends on schema there is complex query that show tables splited size (tables , indexes)
SELECT
schema_name,
relname,
pg_size_pretty(table_size) AS size,
table_size
FROM (
SELECT