From 710a3c9672ad8e2c6fedd497c8a4a5749cafdd2a Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Mon, 26 Oct 2015 16:17:25 +0100 Subject: [PATCH] Removes ability to examine all relations for _CDB_Unique_Column_Identifier 173 --- scripts-available/CDB_Helper.sql | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/scripts-available/CDB_Helper.sql b/scripts-available/CDB_Helper.sql index b24e3c3..04d2388 100644 --- a/scripts-available/CDB_Helper.sql +++ b/scripts-available/CDB_Helper.sql @@ -58,8 +58,8 @@ END; $$ LANGUAGE 'plpgsql'; -- UTF8 safe and lenght aware. Find a unique identifier for a column with a given prefix --- and/or suffix and withing a realtion. If no reloid is give, all relations are examined. -CREATE OR REPLACE FUNCTION cartodb._CDB_Unique_Column_Identifier(prefix TEXT, relname TEXT, suffix TEXT, reloid REGCLASS DEFAULT NULL) +-- and/or suffix and withing a realtion. +CREATE OR REPLACE FUNCTION cartodb._CDB_Unique_Column_Identifier(prefix TEXT, relname TEXT, suffix TEXT, reloid REGCLASS) RETURNS TEXT AS $$ DECLARE @@ -88,24 +88,14 @@ BEGIN origident := ident; WHILE i < 100 LOOP - IF reloid IS NOT NULL THEN - SELECT a.attname - INTO rec - FROM pg_class c - JOIN pg_attribute a ON a.attrelid = c.oid - WHERE NOT a.attisdropped - AND a.attnum > 0 - AND c.oid = reloid - AND a.attname = ident; - ELSE - SELECT a.attname - INTO rec - FROM pg_class c - JOIN pg_attribute a ON a.attrelid = c.oid - WHERE NOT a.attisdropped - AND a.attnum > 0 - AND a.attname = ident; - END IF; + SELECT a.attname + INTO rec + FROM pg_class c + JOIN pg_attribute a ON a.attrelid = c.oid + WHERE NOT a.attisdropped + AND a.attnum > 0 + AND c.oid = reloid + AND a.attname = ident; IF NOT FOUND THEN RETURN ident;