# Help to use Python do insert variable in SQL code

**URL:** <https://forum.knime.com/t/help-to-use-python-do-insert-variable-in-sql-code/63058>\
**Category:** KNIME Analytics Platform\
**Created:** [March 4, 2023, 2:37pm UTC](https://forum.knime.com/t/help-to-use-python-do-insert-variable-in-sql-code/63058 "2023-03-04T14:37:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aldemir](https://forum-cdn.knime.com/user_avatar/forum.knime.com/aldemir/32/53929_2.png) [@Aldemir](https://forum.knime.com/u/Aldemir)\
**Post date:** [March 4, 2023, 2:37pm UTC](https://forum.knime.com/t/help-to-use-python-do-insert-variable-in-sql-code/63058/1 "2023-03-04T14:37:46Z")

</div>

I turned an array into a string. But I need to take this string to the next node in order to use it in a SQL. Any tips on how to do this?

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/0/c/0c0eaa19b4bfcaba91339463e56109b0722efff5.png)

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/7/c/7c31c85c32e96b325896c9fef0b938fc19350020.png)

I want to use this string like I’m doing with Period1. Instead of typing, use a list that’s in a file that I’m going to read.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/e/b/eb8d336d5bb554d998edc65a4188607d87c25d19.png)

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/6/1/61c6240cdd2b3e057281298fda823f8e77cc3e16.png)

If there is another simpler way to do it, let me know.

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [March 4, 2023, 4:34pm UTC](https://forum.knime.com/t/help-to-use-python-do-insert-variable-in-sql-code/63058/2 "2023-03-04T16:34:47Z")

</div>

@Aldemir you can export data from within the Python node as Flow Variables or as a dataframe (from a pandas dataframe). The code would look something like this:

```auto
import knime.scripting.io as knio
import numpy as np
import pandas as pd

# bring your string to a Flow Variable
knio.flow_variables['var_txt_cbi'] = txt_cbi

# bring your content to a pandas data frame
output_table = pd.DataFrame({'column_txt_cbi': [txt_cbi]})

# bring the dataframe back to KNIME
knio.output_tables[0] = knio.Table.from_pandas(output_table)

```

Question is would you need Python for what you want to do or are there KNIME nodes that also can do the transformation you want. In any case if you want to use more KNIME and Python it might be good to take a look at the relevant guides. Also I would recommend this sample workflow that presents examples for things you can do with KNIME and Python:

> **[Simple example to make a random forest model with new Python Scrip in KNIME...](https://hub.knime.com/mlauber71/spaces/Public/latest/kn_example_python_iris_2022~HIFbIx26objNVR40)**
>
> Simple example to make a random forest model with new Python Scrip in KNIME 4.6 using the iris dataset. Saving and reusing the model with Pickle Also creating …

Also there is a Space on the KNIME hub with some more examples how to use KNIME and Python:

> **[knime/Python Script Space – 01\_Getting\_Started](https://hub.knime.com/knime/spaces/Python%20Script%20Space/latest/01_Getting_Started~22Yuq_ZDE8fquNgw/)**
>
> contains 5 items

* * *

Data Transfer between KNIME & Python Just Got Faster

> **[Data Transfer between KNIME & Python Just Got Faster | KNIME](https://www.knime.com/blog/python-integration-for-fast-data-transfer)**
>
> The KNIME Python Integration (Labs) boosts performance making Python just as fast in KNIME as it is anywhere else. There is no latency when KNIME transfers tables to Python nodes.

KNIME Python Integration Guide  
[https://docs.knime.com/latest/python\_installation\_guide/#\_introduction](https://docs.knime.com/latest/python_installation_guide/#_introduction)

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [March 11, 2023, 4:35pm UTC](https://forum.knime.com/t/help-to-use-python-do-insert-variable-in-sql-code/63058/3 "2023-03-11T16:35:45Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
