Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9ff282b17 | ||
|
|
f251e12d35 | ||
|
|
5a3b93fd6b | ||
|
|
eaee6d3d70 | ||
|
|
7840e7c50b | ||
|
|
5b0a7bf9ad | ||
|
|
2ef6d5901e | ||
|
|
3d37b3646e | ||
|
|
51d48c7629 | ||
|
|
25a0e5ec68 | ||
|
|
daa61a6aa8 | ||
|
|
723a08e814 |
@@ -19,7 +19,7 @@ in which those scripts are loaded.
|
||||
|
||||
Scripts would be best coded in a way to be usable both for creation
|
||||
and upgrade of the objects. This means using CREATE OR REPLACE for
|
||||
the functions, and whatever it takes to check existance of any previous
|
||||
the functions, and whatever it takes to check existence of any previous
|
||||
version of objects in other cases.
|
||||
|
||||
When used as an extension (probably always from version 0.2.0 onwards)
|
||||
@@ -27,8 +27,8 @@ all the objects will be installed in a "cartodb" schema. Take this into
|
||||
account to fully-qualify internal calls to avoid (possibly dangerous)
|
||||
name clashes.
|
||||
|
||||
Every new feature (as well as bugfixes) should come with a testcase,
|
||||
see next session.
|
||||
Every new feature (as well as bugfixes) should come with a test case,
|
||||
see next section.
|
||||
|
||||
Writing testcases
|
||||
-----------------
|
||||
@@ -58,4 +58,3 @@ Starting with 0.2.0, the in-place reload can be done with an ad-hoc function:
|
||||
```sql
|
||||
SELECT cartodb.cdb_extension_reload();
|
||||
```
|
||||
|
||||
7
Makefile
7
Makefile
@@ -1,7 +1,7 @@
|
||||
# cartodb/Makefile
|
||||
|
||||
EXTENSION = cartodb
|
||||
EXTVERSION = 0.3.6
|
||||
EXTVERSION = 0.4.1
|
||||
|
||||
SED = sed
|
||||
|
||||
@@ -26,6 +26,8 @@ UPGRADABLE = \
|
||||
0.3.3 \
|
||||
0.3.4 \
|
||||
0.3.5 \
|
||||
0.3.6 \
|
||||
0.4.0 \
|
||||
$(EXTVERSION)dev \
|
||||
$(EXTVERSION)next \
|
||||
$(END)
|
||||
@@ -36,7 +38,6 @@ UPGRADES = \
|
||||
$(SED) 's/$$/--$(EXTVERSION).sql/' | \
|
||||
$(SED) 's/ /--$(EXTVERSION).sql $(EXTENSION)--/g')
|
||||
|
||||
REV=$(shell git describe)
|
||||
GITDIR=$(shell test -d .git && echo '.git' || cat .git | $(SED) 's/^gitdir: //')
|
||||
|
||||
DATA_built = \
|
||||
@@ -78,7 +79,7 @@ $(EXTENSION).control: $(EXTENSION).control.in Makefile
|
||||
$(SED) -e 's/@@VERSION@@/$(EXTVERSION)/' $< > $@
|
||||
|
||||
cartodb_version.sql: cartodb_version.sql.in Makefile $(GITDIR)/index
|
||||
$(SED) -e 's/@@VERSION@@/$(EXTVERSION) $(REV)/' $< > $@
|
||||
$(SED) -e 's/@@VERSION@@/$(EXTVERSION)/' $< > $@
|
||||
|
||||
legacy_regress: $(REGRESS_OLD) Makefile
|
||||
mkdir -p sql/test/
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
0.4.0 (2014-08-27)
|
||||
------------------
|
||||
Added CDB_Math_Mode function
|
||||
Changes in versioning: no revision is attached so it no longer uses `git describe` for the version.
|
||||
|
||||
0.3.6 (2014-08-11)
|
||||
------------------
|
||||
Dummy release to solve some issues with cdb branch/tag
|
||||
@@ -20,12 +20,16 @@ Dependencies
|
||||
Install
|
||||
-------
|
||||
|
||||
make all install
|
||||
```sh
|
||||
make all install
|
||||
```
|
||||
|
||||
Test installation
|
||||
-----------------
|
||||
|
||||
make installcheck
|
||||
```sh
|
||||
make installcheck
|
||||
```
|
||||
|
||||
NOTE: if ``test_ddl_triggers`` fails it's likely due to an incomplete
|
||||
installation of schema_triggers: you need to add ``schema_triggers.so``
|
||||
|
||||
@@ -67,6 +67,7 @@ DECLARE
|
||||
had_column BOOLEAN;
|
||||
i INTEGER;
|
||||
new_name TEXT;
|
||||
cartodb_id_name TEXT;
|
||||
BEGIN
|
||||
<< cartodb_id_setup >>
|
||||
LOOP --{
|
||||
@@ -75,6 +76,7 @@ BEGIN
|
||||
sql := 'ALTER TABLE ' || reloid::text || ' ADD cartodb_id SERIAL NOT NULL UNIQUE';
|
||||
RAISE DEBUG 'Running %', sql;
|
||||
EXECUTE sql;
|
||||
cartodb_id_name := 'cartodb_id';
|
||||
EXIT cartodb_id_setup;
|
||||
EXCEPTION
|
||||
WHEN duplicate_column THEN
|
||||
@@ -114,6 +116,7 @@ BEGIN
|
||||
BEGIN
|
||||
RAISE DEBUG 'Running %', sql;
|
||||
EXECUTE sql;
|
||||
cartodb_id_name := 'cartodb_id';
|
||||
EXIT cartodb_id_setup;
|
||||
EXCEPTION
|
||||
WHEN unique_violation OR not_null_violation THEN
|
||||
@@ -139,13 +142,14 @@ BEGIN
|
||||
WHEN others THEN
|
||||
RAISE EXCEPTION 'Cartodbfying % (renaming cartodb_id): % (%)', reloid, SQLERRM, SQLSTATE;
|
||||
END;
|
||||
cartodb_id_name := new_name;
|
||||
EXIT rename_column;
|
||||
END LOOP; --}
|
||||
CONTINUE cartodb_id_setup;
|
||||
END IF;
|
||||
END LOOP; -- }
|
||||
|
||||
-- Try to copy data from new name if possible
|
||||
-- Try to copy data from new name if possible
|
||||
IF new_name IS NOT NULL THEN
|
||||
RAISE NOTICE 'Trying to recover data from % column', new_name;
|
||||
BEGIN
|
||||
@@ -185,6 +189,18 @@ BEGIN
|
||||
END;
|
||||
END IF;
|
||||
|
||||
-- Set primary key of the table if not already present (e.g. tables created from SQL API)
|
||||
IF cartodb_id_name IS NULL THEN
|
||||
RAISE EXCEPTION 'Cartodbfying % (Didnt get cartodb_id field name)', reloid;
|
||||
END IF;
|
||||
BEGIN
|
||||
sql := 'ALTER TABLE ' || reloid::text || ' ADD PRIMARY KEY (cartodb_id)';
|
||||
EXECUTE sql;
|
||||
EXCEPTION
|
||||
WHEN others THEN
|
||||
RAISE DEBUG 'Table % Already had PRIMARY KEY', reloid;
|
||||
END;
|
||||
|
||||
END;
|
||||
$$ LANGUAGE PLPGSQL;
|
||||
|
||||
|
||||
26
scripts-available/CDB_Math.sql
Normal file
26
scripts-available/CDB_Math.sql
Normal file
@@ -0,0 +1,26 @@
|
||||
-- CartoDB Math SQL functions
|
||||
|
||||
|
||||
-- Mode
|
||||
-- https://wiki.postgresql.org/wiki/Aggregate_Mode
|
||||
|
||||
CREATE OR REPLACE FUNCTION cartodb._CDB_Math_final_mode(anyarray)
|
||||
RETURNS anyelement AS
|
||||
$BODY$
|
||||
SELECT a
|
||||
FROM unnest($1) a
|
||||
GROUP BY 1
|
||||
ORDER BY COUNT(1) DESC, 1
|
||||
LIMIT 1;
|
||||
$BODY$
|
||||
LANGUAGE 'sql' IMMUTABLE;
|
||||
|
||||
DROP AGGREGATE IF EXISTS cartodb.CDB_Math_Mode(anyelement);
|
||||
|
||||
CREATE AGGREGATE cartodb.CDB_Math_Mode(anyelement) (
|
||||
SFUNC=array_append,
|
||||
STYPE=anyarray,
|
||||
FINALFUNC=_CDB_Math_final_mode,
|
||||
INITCOND='{}'
|
||||
);
|
||||
|
||||
1
scripts-enabled/220-CDB_Math.sql
Symbolic link
1
scripts-enabled/220-CDB_Math.sql
Symbolic link
@@ -0,0 +1 @@
|
||||
../scripts-available/CDB_Math.sql
|
||||
4
test/CDB_MathTest.sql
Normal file
4
test/CDB_MathTest.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
SELECT cdb_math_mode(a) from unnest(ARRAY[1,2,2,3]) a;
|
||||
SELECT cdb_math_mode(a) from unnest(ARRAY[1,2,3]) a;
|
||||
SELECT cdb_math_mode(a) from unnest(ARRAY[1]) a;
|
||||
3
test/CDB_MathTest_expect
Normal file
3
test/CDB_MathTest_expect
Normal file
@@ -0,0 +1,3 @@
|
||||
2
|
||||
1
|
||||
1
|
||||
@@ -7,7 +7,7 @@ ERROR: Quota exceeded by 3.9990234375KB
|
||||
|
||||
INSERT 0 1024
|
||||
8
|
||||
ERROR: Quota exceeded by 103.9921875KB
|
||||
ERROR: Quota exceeded by 123.9921875KB
|
||||
0
|
||||
INSERT 0 1
|
||||
DROP TABLE
|
||||
|
||||
Reference in New Issue
Block a user