Skip to content

Instantly share code, notes, and snippets.

@mewwts

mewwts/query.sql Secret

Created November 25, 2020 16:48
Show Gist options
  • Save mewwts/704663e19a21bc51864f3298f09a18c0 to your computer and use it in GitHub Desktop.
Save mewwts/704663e19a21bc51864f3298f09a18c0 to your computer and use it in GitHub Desktop.
INSERT INTO foreign.labels (address, labels)
SELECT address_id, ARRAY_AGG(name) AS labels
FROM labels
GROUP BY 1
LIMIT 100;
CREATE TABLE labels (
id integer NOT NULL,
address_id bytea NOT NULL,
name text NOT NULL,
author character varying(50) NOT NULL,
type text NOT NULL,
source text,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT lowercase_name CHECK ((name = lower(name))),
CONSTRAINT lowercase_type CHECK ((type = lower(type))),
CONSTRAINT whitespace_name CHECK ((regexp_replace(btrim(name, ' '::text), '(\s+)'::text, ' '::text, 'g'::text) = name)),
CONSTRAINT whitespace_type CHECK ((regexp_replace(btrim(type, ' '::text), '(\s+)'::text, ' '::text, 'g'::text) = type))
);
CREATE INDEX labels_label ON labels USING BTREE (name);
CREATE INDEX labels_label_type ON labels USING BTREE (type);
CREATE INDEX labels_address ON labels USING HASH (address_id);
CREATE INDEX labels_source ON labels USING BTREE (source);
CREATE TABLE labels.labels (
address bytea PRIMARY KEY,
labels text[]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment