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: content/connectivity/sql/_index.en.md
+38Lines changed: 38 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,7 @@ weight: 9
19
19
-[Building a ConditionalLoader](#building-a-conditionalloader)
20
20
-[Advanced usage](#advanced-usage)
21
21
-[Using params in your queries](#using-params-in-your-queries)
22
+
-[Using an unknown number of parameters](#using-an-unknown-number-of-parameters)
22
23
-[Creating before and after queries](#creating-before-and-after-queries)
23
24
24
25
---
@@ -237,6 +238,43 @@ sql:
237
238
# ...
238
239
```
239
240
241
+
### Using an unknown number of parameters
242
+
243
+
In some cases, you may not know in advance how many parameters you will need to enter,
244
+
for example if you are searching using an `IN` with many values.
245
+
246
+
Using `from` instead of `value` will bind as many parameters as there are values in the path.
247
+
248
+
And use [the expression `inSql(path, parameter_name)`](../../feature/expression-language/satellite-expression-functions/#list-of-available-functions) to prepare the values in the query.
249
+
250
+
```yaml
251
+
sql:
252
+
loader:
253
+
query: '@="SELECT * FROM category WHERE id " ~ inSql(input["codes_list"], "identifier") ~ "'
254
+
parameters:
255
+
identifier:
256
+
from: '@=input["codes_list"]'
257
+
# ...
258
+
```
259
+
260
+
If at runtime there are 4 values under `[codes_list]`, this would be equivalent to writing:
261
+
262
+
```yaml
263
+
sql:
264
+
loader:
265
+
query: 'SELECT * FROM category WHERE id IN (:identifier_0, :identifier_1, :identifier_2, :identifier_3)'
266
+
parameters:
267
+
identifier_0:
268
+
value: '@=input["codes_list"][0]'
269
+
identifier_1:
270
+
value: '@=input["codes_list"][1]'
271
+
identifier_2:
272
+
value: '@=input["codes_list"][2]'
273
+
identifier_3:
274
+
value: '@=input["codes_list"][3]'
275
+
# ...
276
+
```
277
+
240
278
### Creating before and after queries
241
279
242
280
In some cases, you may need to run queries in order to best prepare for the execution of your pipeline.
| env(`string` name): `string|false`| Gets the value of an environment variable |
44
+
| envAsFile(`string` name): `string`| Create a file whose name is an environment variable |
45
+
| file(`string` name): `string`| Create a file |
46
+
| base64Decode(`string` name): `string|false`| Decodes data encoded with Base64 |
47
+
| temporaryFile(`string` name): `resource`| Create a temporary file |
48
+
| inSql(`array` path, `string` parameterName): `string`| Writes "IN (...)" with as many parameters as there are values under `path`, in the format: `:parameterName_0`, `:parameterName_1`... To be used in a SQL query [when searching among an unknown number of values](../../../connectivity/sql/#using-an-unknown-number-of-parameters). |
0 commit comments