From f2dae651b3733d21d7a720b430f4f449fa92059c Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Mon, 1 Jul 2019 16:58:24 +0200 Subject: [PATCH] More complete sync table example --- doc/CDB_SyncTable.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/CDB_SyncTable.md b/doc/CDB_SyncTable.md index 7069747..08d7bbe 100644 --- a/doc/CDB_SyncTable.md +++ b/doc/CDB_SyncTable.md @@ -22,14 +22,28 @@ Import some data using COPY FROM into a temporary table, then synchronize a tabl finally delete the temporary table. This could be used import and update some data periodically while allowing to add columns to the data that will be preserved across updates. - ```sql -CREATE tmp_pois(cartodb_id int, name text, type text, longitude double precision, latitude double precision); +CREATE tmp_pois(cartodb_id int, name text, type text, longitude double precision, latitude double precision, rank int); COPY tmp_pois FROM '/tmp/pois.csv'; SELECT CDB_SyncTable('tmp_pois', 'public', 'pois'); DROP TABLE tmp_pois; ``` +Now we could perform some changes to the `pois` to maintain our own ranking: + +```sql +UPDATE pois SET rank = random()*4 + 1; +``` + +Then, if the source were updated at `/tmp/pois.csv` we could synchronize with it while maintaining our `rank` values with: + +```sql +CREATE tmp_pois(cartodb_id int, name text, type text, longitude double precision, latitude double precision, rank int); +COPY tmp_pois FROM '/tmp/pois.csv'; +SELECT CDB_SyncTable('tmp_pois', 'public', 'pois', '{rank}'); +DROP TABLE tmp_pois; +``` + #### Arguments ```