Skip to content

Instantly share code, notes, and snippets.

View schwartzmx's full-sized avatar
👓

Phil Schwartz schwartzmx

👓
View GitHub Profile
SELECT c.relname AS "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'm' THEN 'materialized view' ELSE 'view' END AS "Engine",
pg_relation_size(c.oid) AS "Data_length",
pg_total_relation_size(c.oid) - pg_relation_size(c.oid) AS "Index_length",
obj_description(c.oid, 'pg_class') AS "Comment",
CASE WHEN c.relhasoids THEN 'oid' ELSE '' END AS "Oid",
c.reltuples as "Rows",
n.nspname
FROM pg_class c
JOIN pg_namespace n ON(n.nspname = current_schema() AND n.oid = c.relnamespace)
@schwartzmx
schwartzmx / dict_get_first.py
Created August 25, 2021 22:41
Dumb, probably unnecessary, helper for looking up a value from a dict for known permutations of a key, or fallback keys. Rather than `dict.get('Key', dict.get('KEY'))` use `get_first(dict, 'Key', 'KEY')` - save yourself 3 keystrokes in the case of 2 keys, more as the # of keys grow! :wow: /s
from typing import Any, Dict, Optional
def get_first(d: Dict[Any, Any], *keys: Any) -> Optional[Any]:
"""Return the first value from d that is not None utilizing the *keys as key lookups.
If no value can be found for any key, returns None.
Example:
>>> d = {
'tesT': 1,
'TeST': 2,