Skip to main content
Best Answer

Truncate table before insert

  • November 9, 2021
  • 2 replies
  • 363 views

coldon
Contributor

I am trying to do an insert to CARTO table. It is mandatory to not drop the table because it is necessary anytime a table is created to make a specific SQL statement.

This table just has to have the last insert values so a truncate command is required.

I have tried with a SQL Executor with two statements. Truncate and Insert. What SQL Executor does is a truncate for every insert. At the end I have a table with only one row, the last value inserted.

Any ideas?

Best answer by nielsgerrits

You can use 2 SQLExecutors, one for one truncate and the other for the inserts. Using a Sampler and a FeatureHolder you should be able to run the truncate statement once and the insert statements after the truncate statement.

 

2021-11-09_15h24_43 

As an alternative you could use an Aggregator to merge all insertrows in one feature, then add a truncaterow above it.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

nielsgerrits
VIP
Forum|alt.badge.img+64
  • Best Answer
  • November 9, 2021

You can use 2 SQLExecutors, one for one truncate and the other for the inserts. Using a Sampler and a FeatureHolder you should be able to run the truncate statement once and the insert statements after the truncate statement.

 

2021-11-09_15h24_43 

As an alternative you could use an Aggregator to merge all insertrows in one feature, then add a truncaterow above it.


coldon
Contributor
  • Author
  • Contributor
  • November 10, 2021

Got it! Thank you!