Skip to content

Instantly share code, notes, and snippets.

@jatorre
Last active December 11, 2015 04:18
Show Gist options
  • Save jatorre/4543823 to your computer and use it in GitHub Desktop.
Save jatorre/4543823 to your computer and use it in GitHub Desktop.
http://viz2.cartodb.com/api/v2/sql?api_key=XXXXXXX&q=
-- Example SQL to create a table named new_table. Replace new_table with whatever name you want
CREATE TABLE new_table
(
--Data types we recommend using: text, integer, float(8), boolean, timestamp without time zone
barrio text,
perimetro numeric,
area numeric,
comuna integer,
-- These fields are mandatory, do not remove
-- The geometry type could be MultiPolygon, MultiLineString or Point (Nothing else)
the_geom geometry(MultiPolygon,4326),
cartodb_id serial NOT NULL,
created_at timestamp without time zone DEFAULT now(),
updated_at timestamp without time zone DEFAULT now(),
the_geom_webmercator geometry(MultiPolygon,3857),
CONSTRAINT new_table_pkey PRIMARY KEY (cartodb_id)
)
WITH (
OIDS=FALSE
);
--We need to create all these indexes, replace new_table for the name of your new table
CREATE INDEX new_table_the_geom_webmercator_idx
ON new_table
USING gist
(the_geom_webmercator);
CREATE TRIGGER cache_checkpoint
BEFORE INSERT OR UPDATE OR DELETE OR TRUNCATE
ON new_table
FOR EACH STATEMENT
EXECUTE PROCEDURE update_timestamp();
CREATE TRIGGER test_quota
BEFORE INSERT OR UPDATE
ON new_table
FOR EACH STATEMENT
EXECUTE PROCEDURE check_quota();
CREATE TRIGGER update_the_geom_webmercator_trigger
BEFORE INSERT OR UPDATE OF the_geom
ON new_table
FOR EACH ROW
EXECUTE PROCEDURE update_the_geom_webmercator();
CREATE TRIGGER update_updated_at_trigger
BEFORE UPDATE
ON new_table
FOR EACH ROW
EXECUTE PROCEDURE update_updated_at();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment