-
-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Insert with parameters #166
Comments
You should be able to perform INSERT INTO from any defined dataframe passed to the query function.
|
Thank you, this is a really smart solution. |
It seems I can't access other databases from the table query function. For example, the following code fails with from chdb.session import Session
import chdb.dataframe as cdf
import pandas as pd
client = Session()
client.query("CREATE DATABASE e ENGINE = Atomic;")
res = client.query(
"CREATE TABLE e.hi (a String primary key, b Int32) Engine = MergeTree ORDER BY a;"
)
df = pd.DataFrame({"a": [str("hi")], "b": [32]})
tbl = cdf.Table(dataframe=df)
h = tbl.query("INSERT INTO e.hi SELECT a, b FROM __table__")
sys.exit(0) Do you have any ideas how I could access the database from the table query function? |
I've managed to make this work using dbapi. conn = dbapi.connect()
cur = conn.cursor()
cur.execute("CREATE DATABASE e ENGINE = Atomic;")
cur.execute("CREATE TABLE e.hi (a String primary key, b Int32) Engine = MergeTree ORDER BY a;")
cur.execute("INSERT INTO e.hi (a, b) VALUES (%s, %s);", ["test", 32]) # only use %s, not %i or %d etc
cur.execute("SELECT * FROM e.hi;")
res = cur.fetchall()
# res should be [("test", 32)] With my pull request, you will be able to pass a |
Use case
I want to insert data into a chdb instance by using the query function, or similar.
Is this possible? I'm aware I can just format my values to strings and concatenate them with the query. However, that's prone to sql injection attacks.
The text was updated successfully, but these errors were encountered: