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 TABLE roles ( | |
id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, | |
name text UNIQUE NOT NULL | |
); | |
INSERT INTO roles (name) VALUES | |
('cargill'), | |
('bigfarm'), | |
('farmer') | |
; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
/* | |
This create function script must be run as a user that owns the collections table! | |
By setting SECURITY DEFINER on the function, we are telling Postgres that this function will run | |
with the permissions of the user that created the function rather than the user that is calling the function. | |
Because this does add a bit of security risk, we take a bit of extra precaution and schema qualify | |
any tables that we are referencing and set the SEARCH_PATH to only explicity include pg_catalog and pg_temp schemas. | |
By running the function as the user that owns the collections table, we are able to enable and disable the triggers that are set on | |
that table. |
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
-- Make sure that you do all of this in your own schema | |
-- Postgres has a search path where it is always going to create new things (tables, functions, etc) in the first entry that exists in your search_path | |
SHOW search_path; | |
-- pgstac lives in the pgstac schema, to use pgstac without needing to prefix everything | |
-- you always want to have public in your search_path as that is where all the main things in the database are (including postgis - think of it like /usr/bin) | |
SET SEARCH_PATH to pgstac, public; | |
-- Create your own schema to play with these things | |
CREATE SCHEMA playground; |
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
-- Function to take an x, y, z and turn it into a quadkey text string | |
CREATE OR REPLACE FUNCTION quadkey(zoom int, tx int, ty int) RETURNS text AS $$ | |
DECLARE | |
i int; | |
digit int; | |
quadkey text := ''; | |
mask int; | |
BEGIN | |
FOR i IN REVERSE zoom..1 LOOP | |
digit := 0; |
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 psycopg | |
import os | |
import time | |
# Get a an iterator to use for sample of half million ids cached to a file | |
def sample_ids(): | |
file='sampleids.csv' | |
if not os.path.exists(file): | |
with open(file, 'wb') as f: | |
with psycopg.connect(os.environ.get('PGURL')) as conn: |
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
\set ON_ERROR_STOP ON | |
BEGIN; | |
DROP SCHEMA IF EXISTS anthony_test CASCADE; | |
CREATE SCHEMA anthony_test; | |
SET SEARCH_PATH to anthony_test, public; | |
CREATE TABLE downloads( | |
id bigint GENERATED ALWAYS AS IDENTITY primary key, | |
created_at timestamptz NOT NULL DEFAULT now(), | |
username text NOT NULL, |
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
|
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
|
NewerOlder