You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/modules/components/pages/inputs/sql_raw.adoc
+1-1
Original file line number
Diff line number
Diff line change
@@ -223,7 +223,7 @@ query: SELECT * FROM footable WHERE user_id = $1;
223
223
224
224
=== `args_mapping`
225
225
226
-
A xref:guides:bloblang/about.adoc[Bloblang mapping] which should evaluate to an array of values matching in size to the number of columns specified.
226
+
An optional xref:guides:bloblang/about.adoc[Bloblang mapping] which should evaluate to an array of values matching in size to the number of placeholder arguments in the field `query`.
A list of statements to run in addition to `query`. When specifying multiple statements, they are all executed within a transaction.
295
+
296
+
297
+
*Type*: `array`
298
+
299
+
300
+
=== `queries[].query`
301
+
302
+
The query to execute. The style of placeholder to use depends on the driver, some drivers require question marks (`?`) whereas others expect incrementing dollar signs (`$1`, `$2`, and so on) or colons (`:1`, `:2` and so on). The style to use is outlined in this table:
303
+
304
+
| Driver | Placeholder Style |
305
+
|---|---|
306
+
| `clickhouse` | Dollar sign |
307
+
| `mysql` | Question mark |
308
+
| `postgres` | Dollar sign |
309
+
| `mssql` | Question mark |
310
+
| `sqlite` | Question mark |
311
+
| `oracle` | Colon |
312
+
| `snowflake` | Question mark |
313
+
| `trino` | Question mark |
314
+
| `gocosmos` | Colon |
315
+
316
+
317
+
*Type*: `string`
318
+
319
+
320
+
=== `queries[].args_mapping`
321
+
322
+
An optional xref:guides:bloblang/about.adoc[Bloblang mapping] which should evaluate to an array of values matching in size to the number of placeholder arguments in the field `query`.
Here we query a database for columns of footable that share a `user_id` with the message field `user.id`. A xref:components:processors/branch.adoc[`branch` processor] is used in order to insert the resulting array into the original message at the path `foo_rows`.
131
+
132
+
```yaml
133
+
pipeline:
134
+
processors:
135
+
- mapping: |
136
+
root = this
137
+
# Prevent SQL injection when using unsafe_dynamic_query
138
+
meta table_name = "\"" + metadata("table_name").replace_all("\"", "\"\"") + "\""
139
+
- sql_raw:
140
+
driver: postgres
141
+
dsn: postgres://localhost/postgres
142
+
unsafe_dynamic_query: true
143
+
queries:
144
+
- query: |
145
+
CREATE TABLE IF NOT EXISTS ${!metadata("table_name")} (id varchar primary key, document jsonb);
146
+
- query: |
147
+
INSERT INTO ${!metadata("table_name")} (id, document) VALUES ($1, $2)
148
+
ON CONFLICT (id) DO UPDATE SET document = EXCLUDED.document;
Whether the query result should be discarded. When set to `true` the message contents will remain unchanged, which is useful in cases where you are executing inserts, updates, etc.
300
+
Whether the query result should be discarded. When set to `true` the message contents will remain unchanged, which is useful in cases where you are executing inserts, updates, etc. By default this is true for the last query, and previous queries don't change the results. If set to true for any query but the last one, the subsequent `args_mappings` input is overwritten.
301
+
302
+
303
+
*Type*: `bool`
304
+
305
+
306
+
=== `queries`
307
+
308
+
A list of statements to run in addition to `query`. When specifying multiple statements, they are all executed within a transaction. The output of the processor is always the last query that runs, unless `exec_only` is used.
309
+
310
+
311
+
*Type*: `array`
312
+
313
+
314
+
=== `queries[].query`
315
+
316
+
The query to execute. The style of placeholder to use depends on the driver, some drivers require question marks (`?`) whereas others expect incrementing dollar signs (`$1`, `$2`, and so on) or colons (`:1`, `:2` and so on). The style to use is outlined in this table:
317
+
318
+
| Driver | Placeholder Style |
319
+
|---|---|
320
+
| `clickhouse` | Dollar sign |
321
+
| `mysql` | Question mark |
322
+
| `postgres` | Dollar sign |
323
+
| `mssql` | Question mark |
324
+
| `sqlite` | Question mark |
325
+
| `oracle` | Colon |
326
+
| `snowflake` | Question mark |
327
+
| `trino` | Question mark |
328
+
| `gocosmos` | Colon |
329
+
330
+
331
+
*Type*: `string`
332
+
333
+
334
+
=== `queries[].args_mapping`
335
+
336
+
An optional xref:guides:bloblang/about.adoc[Bloblang mapping] which should evaluate to an array of values matching in size to the number of placeholder arguments in the field `query`.
Whether the query result should be discarded. When set to `true` the message contents will remain unchanged, which is useful in cases where you are executing inserts, updates, etc. By default this is true for the last query, and previous queries don't change the results. If set to true for any query but the last one, the subsequent `args_mappings` input is overwritten.
@@ -136,6 +137,14 @@ CREATE TABLE IF NOT EXISTS some_table (
136
137
}
137
138
}
138
139
140
+
typerawQueryStatementstruct {
141
+
staticstring
142
+
dynamic*service.InterpolatedString
143
+
144
+
argsMapping*bloblang.Executor// optional
145
+
execOnlybool
146
+
}
147
+
139
148
funcrawQueryField() *service.ConfigField {
140
149
returnservice.NewStringField("query").
141
150
Description("The query to execute. The style of placeholder to use depends on the driver, some drivers require question marks (`?`) whereas others expect incrementing dollar signs (`$1`, `$2`, and so on) or colons (`:1`, `:2` and so on). The style to use is outlined in this table:"+`
Description("An optional xref:guides:bloblang/about.adoc[Bloblang mapping] which should evaluate to an array of values matching in size to the number of placeholder arguments in the field `query`.").
Example("SELECT * FROM footable WHERE user_id = $1;")).
39
-
Field(service.NewBloblangField("args_mapping").
40
-
Description("A xref:guides:bloblang/about.adoc[Bloblang mapping] which should evaluate to an array of values matching in size to the number of columns specified.").
0 commit comments