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
/* Useful celery config. | |
app = Celery('tasks', | |
broker='redis://localhost:6379', | |
backend='redis://localhost:6379') | |
app.conf.update( | |
CELERY_TASK_RESULT_EXPIRES=3600, | |
CELERY_QUEUES=( | |
Queue('default', routing_key='tasks.#'), |
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
CREATE OR REPLACE FUNCTION public.list_public_tables() | |
RETURNS TABLE(name character varying) | |
LANGUAGE plpgsql | |
AS $function$ | |
BEGIN | |
FOR name IN SELECT quote_ident(table_name) FROM information_schema.tables WHERE table_schema = 'public' LOOP | |
RETURN NEXT; | |
END LOOP; | |
END; |
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
BEGIN; | |
DROP TRIGGER IF EXISTS accumulate_ait | |
on accumulate; | |
DROP FUNCTION IF EXISTS adapt_to_service(); | |
DROP TABLE IF EXISTS accumulate CASCADE; | |
CREATE TABLE IF NOT EXISTS accumulate ( | |
id bigint NOT NULL, | |
monies bigint, |
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
BEGIN; | |
DROP FUNCTION IF EXISTS slugify CASCADE; | |
DROP TRIGGER IF EXISTS slugify | |
ON talks; | |
DROP TABLE IF EXISTS talks CASCADE; | |
CREATE | |
OR REPLACE FUNCTION slugify(intake TEXT) | |
RETURNS TEXT AS |
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 | |
( n % 2 ) :: TEXT, | |
ARRAY_AGG ( n ) | |
FROM | |
generate_series ( 1, 10 ) n | |
GROUP BY | |
( n % 2 ) :: TEXT; |
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
-- create the needed sequence | |
CREATE SEQUENCE table_id_seq; | |
-- change the public to schema of choice | |
CREATE OR REPLACE FUNCTION public.next_id(OUT result bigint) AS $$ | |
DECLARE | |
our_epoch bigint := 1314220021721; | |
seq_id bigint; | |
now_millis bigint; | |
shard_id int := 5; |
OlderNewer