Merge remote-tracking branch 'origin/master' into remove_schema_triggers
This commit is contained in:
@@ -152,12 +152,12 @@ BEGIN
|
||||
-- Copy existing values to new field
|
||||
-- NOTE: using ALTER is a workaround to a PostgreSQL bug and is also known to be faster for tables with many rows
|
||||
-- See http://www.postgresql.org/message-id/20140530143150.GA11051@localhost
|
||||
sql := Format('ALTER TABLE %s ALTER cartodb_id TYPE int USING %I', reloid::text, new_name);
|
||||
sql := Format('ALTER TABLE %s ALTER cartodb_id TYPE int USING %I::integer', reloid::text, new_name);
|
||||
RAISE DEBUG 'Running %', sql;
|
||||
EXECUTE sql;
|
||||
|
||||
-- Find max value
|
||||
sql := Format('SELECT max(cartodb_id) FROM %s', reloid::text);
|
||||
sql := Format('SELECT coalesce(max(cartodb_id), 0) as max FROM %s', reloid::text);
|
||||
RAISE DEBUG 'Running %', sql;
|
||||
EXECUTE sql INTO rec;
|
||||
|
||||
@@ -166,7 +166,7 @@ BEGIN
|
||||
AS seq INTO rec2;
|
||||
|
||||
-- Reset sequence name
|
||||
sql := Format('ALTER SEQUENCE %s RESTART WITH %d', rec2.seq::text, rec.max + 1);
|
||||
sql := Format('ALTER SEQUENCE %s RESTART WITH %s', rec2.seq::text, rec.max + 1);
|
||||
RAISE DEBUG 'Running %', sql;
|
||||
EXECUTE sql;
|
||||
|
||||
@@ -504,7 +504,7 @@ BEGIN
|
||||
IF rec.atttypid IN (20,21,23) THEN
|
||||
|
||||
-- And it's a unique primary key! Done!
|
||||
IF rec.indisprimary AND rec.indisunique AND rec.attnotnull THEN
|
||||
IF (rec.indisprimary OR rec.indisunique) AND rec.attnotnull THEN
|
||||
RAISE DEBUG 'CDB(_CDB_Has_Usable_Primary_ID): %', Format('found good ''%s''', const.pkey);
|
||||
RETURN true;
|
||||
|
||||
@@ -1068,8 +1068,8 @@ BEGIN
|
||||
-- Add now add all the rest of the columns
|
||||
-- by selecting their names into an array and
|
||||
-- joining the array with a comma
|
||||
SELECT
|
||||
',' || array_to_string(array_agg(a.attname),',') AS column_name_sql,
|
||||
SELECT
|
||||
',' || array_to_string(array_agg(Format('%I',a.attname)),',') AS column_name_sql,
|
||||
Count(*) AS count
|
||||
INTO rec
|
||||
FROM pg_class c
|
||||
|
||||
26
scripts-available/CDB_GreatCircle.sql
Normal file
26
scripts-available/CDB_GreatCircle.sql
Normal file
@@ -0,0 +1,26 @@
|
||||
-- Great circle point-to-point routes, based on:
|
||||
-- http://blog.cartodb.com/jets-and-datelines/
|
||||
--
|
||||
CREATE OR REPLACE FUNCTION CDB_GreatCircle(start_point geometry, end_point geometry, max_segment_length NUMERIC DEFAULT 100000)
|
||||
RETURNS geometry AS $$
|
||||
DECLARE
|
||||
line geometry;
|
||||
BEGIN
|
||||
line = ST_Segmentize(
|
||||
ST_Makeline(
|
||||
start_point,
|
||||
end_point
|
||||
)::geography,
|
||||
max_segment_length
|
||||
)::geometry;
|
||||
|
||||
IF ST_XMax(line) - ST_XMin(line) > 180 THEN
|
||||
line = ST_Difference(
|
||||
ST_Shift_Longitude(line),
|
||||
ST_Buffer(ST_GeomFromText('LINESTRING(180 90, 180 -90)', 4326), 0.00001)
|
||||
);
|
||||
END IF;
|
||||
RETURN line;
|
||||
END;
|
||||
$$
|
||||
LANGUAGE 'plpgsql';
|
||||
@@ -64,10 +64,6 @@ DECLARE
|
||||
tabname TEXT;
|
||||
rec RECORD;
|
||||
found BOOL;
|
||||
function_start timestamptz;
|
||||
function_end timestamptz;
|
||||
function_duration float;
|
||||
log_error_verbosity_value text;
|
||||
BEGIN
|
||||
|
||||
IF TG_OP = 'UPDATE' or TG_OP = 'INSERT' THEN
|
||||
@@ -76,8 +72,6 @@ BEGIN
|
||||
tabname = OLD.tabname;
|
||||
END IF;
|
||||
|
||||
function_start := clock_timestamp();
|
||||
|
||||
-- Notify table data update
|
||||
-- This needs a little bit more of research regarding security issues
|
||||
-- see https://github.com/CartoDB/cartodb/pull/241
|
||||
@@ -111,14 +105,7 @@ BEGIN
|
||||
EXIT;
|
||||
END LOOP;
|
||||
IF NOT found THEN RAISE WARNING 'Missing cdb_invalidate_varnish()'; END IF;
|
||||
|
||||
function_end := clock_timestamp();
|
||||
SELECT extract(epoch from (function_end - function_start)) INTO function_duration;
|
||||
SELECT setting INTO log_error_verbosity_value FROM pg_settings WHERE name='log_error_verbosity';
|
||||
SET log_error_verbosity=TERSE;
|
||||
RAISE LOG 'invalidation_duration: %', function_duration::text;
|
||||
PERFORM 'SET log_error_verbosity= ' || log_error_verbosity_value;
|
||||
|
||||
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$
|
||||
|
||||
Reference in New Issue
Block a user