Merge pull request #679 from CartoDB/bug/ch140184/gloval-seven-admin-batch-query-fallback-templates

[ch140184] Update documentation about fallback templates
This commit is contained in:
Shylpx 2021-04-12 14:53:23 +01:00 committed by GitHub
commit 2c5dce2082
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -449,7 +449,7 @@ If a query of a job fails (and onerror fallbacks for that query and job are defi
#### Templates #### Templates
Batch Queries provide a simple way to get the error message and the job identifier to be used in your fallbacks, by using the following templates: Batch Queries provide a simple way to get the error message and the job identifier to be used in your fallbacks defined at the query level, by using the following templates:
- `<%= error_message %>`: will be replaced by the error message raised by the database. - `<%= error_message %>`: will be replaced by the error message raised by the database.
- `<%= job_id %>`: will be replaced by the job identifier that Batch Queries provides. - `<%= job_id %>`: will be replaced by the job identifier that Batch Queries provides.
@ -460,15 +460,13 @@ This is helpful when you want to save error messages into a table:
curl -X POST -H "Content-Type: application/json" -d '{ curl -X POST -H "Content-Type: application/json" -d '{
"query": { "query": {
"query": [{ "query": [{
"query": "UPDATE wrong_table SET price = '$100.00' WHERE company = 'CARTO'" "query": "UPDATE wrong_table SET price = '$100.00' WHERE company = 'CARTO'",
}],
"onerror": "INSERT INTO errors_log (job_id, error_message, date) VALUES ('<%= job_id %>', '<%= error_message %>', NOW())" "onerror": "INSERT INTO errors_log (job_id, error_message, date) VALUES ('<%= job_id %>', '<%= error_message %>', NOW())"
}]
} }
}' "https://{username}.carto.com/api/v2/sql/job" }' "https://{username}.carto.com/api/v2/sql/job"
``` ```
More templates are coming soon.
### Fetching Job Results ### Fetching Job Results
In some scenarios, you may need to fetch the output of a job. If that is the case, wrap the query with `SELECT * INTO`, or `CREATE TABLE AS`. The output is stored in a new table in your database. For example, if using the query `SELECT * FROM airports`: In some scenarios, you may need to fetch the output of a job. If that is the case, wrap the query with `SELECT * INTO`, or `CREATE TABLE AS`. The output is stored in a new table in your database. For example, if using the query `SELECT * FROM airports`: