[GIS] Adding additional columns of data to CartoDB table? (in-place / no merge)

cartodatamerge

Is there any quick way to add some data to a table without either a) merging / replacing the whole thing or b) having to do it one cell at a time ?

example: i have a table loaded now with the counties of Arizona. I would like to add a few columns of county-specific data in-place. I don't want to merge unless i can merge in-place.

the end result would be as if i exported the data, added columns to it (e.g. in google docs), and created a new table using that same data. This is the thing to be avoided.

Best Answer

Yep, you can do it with SQL. Let's say you have two tables containing rows of data. Both have a column called county_code which is shared. To write a column of data from table_2 into table_1 you would run the following SQL,

UPDATE table_1 SET some_new_column = 
  (SELECT 
     some_old_column 
   FROM table_2 
   WHERE 
     county_code = table_1.county_code 
   LIMIT 1)

You would have to create the column new_column in table_1 and give it the same type (date, string, numeric) as the some_old_column in table_2.

You can do this a column at a time to make sure you are doing it okay and then just drop columns from table_2 when you don't need them anymore

Related Question