0

Is there a way to add rows to an existing dataset while importing in a table?

I've have tried inserting directly from an existing dataset but get an issue withe cartodb_id already existing.

  • can you share what you have tried so far? – Cushen Jul 9 '18 at 7:23
  • Welcome to GIS SE, I highly recommend taking this onboarding tour. Among other things, you learn how to ask questions. As requested by @Cushen, we will need to know what you have tried, what errors are you getting and so on. – ramiroaznar Jul 9 '18 at 8:20
2

You need to use the following type of INSERT query; specifying the source and target column for the insert.

This way you can exclude cartodb_id (which is an auto incremented primary key):

INSERT INTO existing_table 
(columna, columnb,   columnc)
SELECT 
columna, columnb,   columnc 
FROM new_table;"

To help you out and save time you can get a comma separated list of field names using the following:

SELECT string_agg(column_name, ', ')
FROM information_schema.columns
WHERE table_name = 'existing_table '

This will return something like this, which you can paste into the insert query:

cartodb_id, columna, columnb, columnc, the_geom, the_geom_webmercator

  • Sorry I should have mentioned I was trying to use the sql api as I'm on the carto engine plan. – HR7 Jul 9 '18 at 4:12
  • @Cushen's answer is also valid if you are using the SQL API. But bear in mind that you will need to add your API Key as parameter in order to modify a table. More info in CARTO docs. – ramiroaznar Jul 9 '18 at 8:22
  • Awesome, good to hear, if you accept the answer you'll let others know that this is the right solution :D – Cushen Jul 16 '18 at 1:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.