From 61d2024eb556651c644b6922593f39bbb545d9eb Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Tue, 3 Jul 2018 15:35:05 +0200 Subject: [PATCH] Make the code nicer by avoiding IF/THEN/ELSE As suggested by Algunenano. --- scripts-available/CDB_Helper.sql | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts-available/CDB_Helper.sql b/scripts-available/CDB_Helper.sql index f582308..00ef341 100644 --- a/scripts-available/CDB_Helper.sql +++ b/scripts-available/CDB_Helper.sql @@ -165,12 +165,11 @@ $$ LANGUAGE 'plpgsql' IMMUTABLE PARALLEL SAFE; CREATE OR REPLACE FUNCTION cartodb._CDB_Table_Exists(table_name_with_optional_schema TEXT) RETURNS bool AS $$ +DECLARE + table_exists bool := false; BEGIN - IF EXISTS(SELECT * FROM pg_class WHERE table_name_with_optional_schema::regclass::oid = oid AND relkind = 'r') THEN - RETURN true; - ELSE - RETURN false; - END IF; + table_exists := EXISTS(SELECT * FROM pg_class WHERE table_name_with_optional_schema::regclass::oid = oid AND relkind = 'r'); + RETURN table_exists; EXCEPTION WHEN invalid_schema_name OR undefined_table THEN RETURN false;