Good to know. sql = ''' select id, true is true true_is_true, true = true true_eq_true, false is false false_is_false, false = false false_eq_false, true is false true_is_false, true = false true_eq_false, false is true false_is_true, false = true false_eq_true, null = true null_eq_true, null is true null_is_true, null = false null_eq_false, null is false null_is_false, true is null true_is_null, true = null true_eq_null, false is null false_is_null, false = null false_eq_null, null is null null_is_null, null = null null_eq_null from blahblah limit 1 ''' db....

(updated February 26, 2023) · 1 min · 126 words · Michal Piekarczyk

subtract intervals from dates although in postgresql you can freely add/subtract dates/timestamps and intervals, SELECT '2001-01-01'::timestamp + '1 year'::interval; in mysql land you need to do use date_sub and date_add date_sub('2019-06-30' , interval 90 days) Subtract dates Also in postgresql you can just subtract dates, '2021-01-01'::date - '2021-05-01'::date And in mysql to do this you can do DATEDIFF('2021-01-01', '2021-05-01')

(updated February 26, 2023) · 1 min · 59 words · Michal Piekarczyk

Create a new user username = 'new_user_foo' passw = input() sql = "CREATE USER {} WITH PASSWORD '{}' ".format(username, passw) Make some quick grants tables = ['table1', 'table_foo', ] username = 'xx' grant_queries = [q.format(username) for q in ["GRANT CONNECT ON DATABASE mydb TO {}", "GRANT USAGE ON SCHEMA public TO {}",] + ["GRANT SELECT ON {} TO ".format(t) + " {} " for t in tables]] check exissting users select * from pg_user update user password ; change ALTER USER user_name WITH PASSWORD 'new_password'; can use input() here too actually Check Existing Grants / permissions The user running this query might not be able to see all the rows SELECT table_catalog, table_schema, table_name, privilege_type, grantee FROM information_schema....

(updated February 26, 2023) · 1 min · 190 words · Michal Piekarczyk

lpad is the func to make sure a month is always two digits as an example. select concat( extract (year from foo.timestamp)::text, lpad (extract (month from foo.timestamp)::text, 2, '0') ) as yearmonth, count(1) from foo where group by yearmonth order by yearmonth asc yearmonth count 202005 5208 202006 8584 202007 7780 202008 5382 202009 3635 202010 2791 202011 1284 202012 2704 202101 2416 202102 1964 202103 2554 202104 2935 202105 2909 202106 160

(updated February 26, 2023) · 1 min · 73 words · Michal Piekarczyk

Checking sha256 For older versions of sshd awk '{print $2}' /etc/sshd/ssh_host_rsa_key.pub | base64 -d | sha256sum -b | awk '{print $1}' | xxd -r -p | base64 Newer sshd ssh-keygen -l -f key.pub -E (sha256|md5)

(updated February 26, 2023) · 1 min · 35 words · Michal Piekarczyk