This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Terminate any existing connections to `thedb` | |
SELECT | |
pg_terminate_backend(pg_stat_activity.pid) | |
FROM | |
pg_stat_activity | |
WHERE | |
pg_stat_activity.datname = 'thedb' | |
AND pid <> pg_backend_pid(); | |
-- Now go ahead and drop the database, `thedb` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
row_to_json(details) | |
FROM | |
( | |
SELECT | |
ARRAY[ 1, | |
2, | |
3 ] as arrays, | |
'Some information' AS text | |
) details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select date '2018-09-18' - date '1990-11-22' AS difference; | |
select date '1990-11-22' + 10162 AS difference; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT ASCII('<'), CHR(60), regexp_split_to_array(md5(random() :: TEXT), '') AS value | |
FROM generate_series(1, 3) | |
ORDER BY random() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- get functions | |
SELECT 'DROP FUNCTION IF EXISTS ' || ROUTINE_NAME || ' CASCADE;' | |
FROM information_schema.routines | |
WHERE routine_type = 'FUNCTION' | |
AND specific_schema = 'public' | |
AND ROUTINE_NAME IN ('ichux') | |
UNION | |
-- get triggers | |
SELECT 'DROP TRIGGER IF EXISTS ' || TRIGGER_NAME || ' ON ' || event_object_table || ';' | |
FROM information_schema.triggers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH first_day AS (SELECT date_trunc('MONTH', NOW()) :: DATE), | |
last_day AS (SELECT (date_trunc('MONTH', (SELECT * FROM first_day)) + INTERVAL '1 MONTH' - | |
INTERVAL '1 DAY') :: DATE) | |
SELECT first_day.*, last_day.* | |
FROM first_day, | |
last_day; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT month_day1 :: DATE AS month_starts, | |
(month_day1 + INTERVAL '1 month' - INTERVAL '1 day') :: DATE AS month_ends, | |
(month_day1 + INTERVAL '1 month') :: DATE AS next_month_starts, | |
(month_day1 + INTERVAL '1 month') :: DATE - month_day1 :: DATE AS days | |
FROM generate_series(DATE '2018-01-01', DATE '2018-12-01', INTERVAL '1 month') AS month_day1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH first_day AS (SELECT date_trunc('MONTH', NOW()) :: DATE AS first_date), | |
last_day AS (SELECT (date_trunc('MONTH', (SELECT * FROM first_day)) + INTERVAL '1 MONTH' - | |
INTERVAL '1 DAY') :: DATE AS last_date) | |
SELECT row_to_json(first_last) | |
FROM (SELECT first_day.*, last_day.* | |
FROM first_day, | |
last_day) first_last; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
printf "\033c" | |
echo '{ | |
"company": "PITCH CARDINAL CODING LIMITED", | |
"rc_no": "1387119", | |
"established": "2017-01-25", | |
"address": "1B, MARKET STREET, OYINGBO" | |
}' | python -m json.tool # > result.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import email.utils | |
import smtplib | |
from email.mime.text import MIMEText | |
# Create the message | |
msg = MIMEText('Hello SMTPD!') | |
msg['To'] = email.utils.formataddr(("Local Mail", "localmail@localhost")) | |
msg['From'] = email.utils.formataddr(('Chukwudi Nwachukwu', 'chukwudinwachukwu@localhost')) | |
msg['Subject'] = 'Local mail using SMTP' |