Fixes NULL max in rec 155

This commit is contained in:
Guido Fioravantti 2015-11-02 11:47:14 +01:00
parent 453b3af872
commit 081ed36aae
3 changed files with 14 additions and 3 deletions

View File

@ -157,7 +157,7 @@ BEGIN
EXECUTE sql; EXECUTE sql;
-- Find max value -- 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; RAISE DEBUG 'Running %', sql;
EXECUTE sql INTO rec; EXECUTE sql INTO rec;
@ -166,7 +166,7 @@ BEGIN
AS seq INTO rec2; AS seq INTO rec2;
-- Reset sequence name -- Reset sequence name
sql := Format('ALTER SEQUENCE %s RESTART WITH %', rec2.seq::text, rec.max + 1); sql := Format('ALTER SEQUENCE %s RESTART WITH %s', rec2.seq::text, rec.max + 1);
RAISE DEBUG 'Running %', sql; RAISE DEBUG 'Running %', sql;
EXECUTE sql; EXECUTE sql;

View File

@ -319,7 +319,7 @@ SELECT CDB_CartodbfyTableCheck('test', 'Table with non unique and null cartodb_i
SELECT cartodb_id, cartodb_id_0 from test; SELECT cartodb_id, cartodb_id_0 from test;
DROP TABLE test; DROP TABLE test;
-- _CDB_create_cartodb_id_column with cartodb_id already present -- _CDB_create_cartodb_id_column with cartodb_id integer already present
CREATE TABLE test (cartodb_id integer); CREATE TABLE test (cartodb_id integer);
SELECT _CDB_Create_Cartodb_ID_Column('test'::regclass); SELECT _CDB_Create_Cartodb_ID_Column('test'::regclass);
@ -327,6 +327,14 @@ SELECT column_name FROM information_schema.columns WHERE table_name = 'test' AND
DROP TABLE test; DROP TABLE test;
-- _CDB_create_cartodb_id_column with cartodb_id text already present
CREATE TABLE test (cartodb_id text);
SELECT _CDB_Create_Cartodb_ID_Column('test'::regclass);
SELECT column_name FROM information_schema.columns WHERE table_name = 'test' AND column_name = '_cartodb_id0';
DROP TABLE test;
-- TODO: table with existing custom-triggered the_geom -- TODO: table with existing custom-triggered the_geom
DROP FUNCTION CDB_CartodbfyTableCheck(regclass, text); DROP FUNCTION CDB_CartodbfyTableCheck(regclass, text);

View File

@ -104,6 +104,9 @@ Table with non unique and null cartodb_id #148 cartodbfied fine
DROP TABLE DROP TABLE
CREATE TABLE CREATE TABLE
DROP TABLE
CREATE TABLE
_cartodb_id0 _cartodb_id0
DROP TABLE DROP TABLE
DROP FUNCTION DROP FUNCTION