Commit 82f10504 authored by Keith Jolley's avatar Keith Jolley

Don't depend on field order in existing scheme cache when updating.

parent 5d64fb0b
......@@ -1044,6 +1044,7 @@ RETURNS VOID AS $$
scheme_locus_count int;
scheme_info RECORD;
scheme_fields text;
unqual_scheme_fields text;
isolate_qry text;
modify_qry text;
qry text;
......@@ -1083,12 +1084,15 @@ RETURNS VOID AS $$
RAISE EXCEPTION 'Scheme has no fields.';
END IF;
scheme_fields:='';
unqual_scheme_fields:='';
FOR i IN 1 .. ARRAY_UPPER(fields,1) LOOP
IF i>1 THEN
scheme_fields:=scheme_fields||',';
unqual_scheme_fields:=unqual_scheme_fields||',';
END IF;
scheme_fields:=scheme_fields||'st.'||fields[i];
unqual_scheme_fields:=unqual_scheme_fields||fields[i];
END LOOP;
IF _method='incremental' THEN
modify_qry:=FORMAT(' AND isolate_id NOT IN (SELECT id FROM %I) ',cache_table);
......@@ -1153,7 +1157,7 @@ RETURNS VOID AS $$
DROP TABLE temp_isolates;
END IF;
IF _method != 'full' THEN
EXECUTE(FORMAT('INSERT INTO %I (SELECT * FROM %I)',cache_table_temp,cache_table));
EXECUTE(FORMAT('INSERT INTO %I (SELECT id,%s FROM %I)',cache_table_temp,unqual_scheme_fields,cache_table));
END IF;
EXECUTE FORMAT('CREATE INDEX on %I(id)',cache_table_temp);
FOR i IN 1 .. ARRAY_UPPER(fields,1) LOOP
......
......@@ -35,6 +35,7 @@ RETURNS VOID AS $$
scheme_locus_count int;
scheme_info RECORD;
scheme_fields text;
unqual_scheme_fields text;
isolate_qry text;
modify_qry text;
qry text;
......@@ -74,12 +75,15 @@ RETURNS VOID AS $$
RAISE EXCEPTION 'Scheme has no fields.';
END IF;
scheme_fields:='';
unqual_scheme_fields:='';
FOR i IN 1 .. ARRAY_UPPER(fields,1) LOOP
IF i>1 THEN
scheme_fields:=scheme_fields||',';
unqual_scheme_fields:=unqual_scheme_fields||',';
END IF;
scheme_fields:=scheme_fields||'st.'||fields[i];
unqual_scheme_fields:=unqual_scheme_fields||fields[i];
END LOOP;
IF _method='incremental' THEN
modify_qry:=FORMAT(' AND isolate_id NOT IN (SELECT id FROM %I) ',cache_table);
......@@ -144,7 +148,7 @@ RETURNS VOID AS $$
DROP TABLE temp_isolates;
END IF;
IF _method != 'full' THEN
EXECUTE(FORMAT('INSERT INTO %I (SELECT * FROM %I)',cache_table_temp,cache_table));
EXECUTE(FORMAT('INSERT INTO %I (SELECT id,%s FROM %I)',cache_table_temp,unqual_scheme_fields,cache_table));
END IF;
EXECUTE FORMAT('CREATE INDEX on %I(id)',cache_table_temp);
FOR i IN 1 .. ARRAY_UPPER(fields,1) LOOP
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment