Results of 1 - 10 of about 18 for fetchAll (0.002 sec.)
- Python Function API 12182
- You can create a DuckDB user-defined function (UDF) from a Python function so it can be used in SQL queries. Similarly to regular functions , they need to have a name, a return type and parameter types. Creating Functions To register a Pyth
...t) -> int: return x + 1 con = duckdb.connect() con.create_function("add_one", add_one) print(con.sql("SELECT add_one(41)").fetchall()) [(42,)] UDFs need NumPy. Without the numpy package, create_function raises InvalidInputException: 'numpy' is required f...T 41 + ?", [x]).fetchone()[0] finally: cur.close() con.create_function("lookup", lookup) print(con.sql("SELECT lookup(1)").fetchall()) [(42,)] Using Partial Functions DuckDB UDFs can also be created with Python partial functions . The arguments the parti...rn x + y with duckdb.connect() as con: con.create_function("add_ten", partial(add, 10)) print(con.sql("SELECT add_ten(5)").fetchall()) [(15,)] Type Annotation When the function has type annotation it's often possible to leave out all of the optional para... - https://man.mtool.work/duckdb/2.0/clients/python/function.html
- Executing SQL in Python 11925
- SQL queries can be executed using the duckdb.sql function. import duckdb duckdb.sql("SELECT 42").show() By default this will create a relation object. The result can be converted to various formats using the result conversion functions. For
...example, the fetchall method can be used to convert the result to Python objects. results = duckdb.sql("SELECT 42").fetchall() print(results) [(...holds the statement's result. A SELECT query that only reads runs each time its relation is read, for example by show() or fetchall() . Query Parameters To parameterize a query, pass the values separately from the SQL string using the execute method. Use...? for positional parameters, supplying the values as a list: con.execute("SELECT * FROM integers WHERE i = ?", [42]).fetchall() Named parameters use the $name syntax, with the values supplied as a dictionary: con.execute("SELECT * FROM integers WHE... - https://man.mtool.work/duckdb/2.0/guides/python/execute_sql.html
- Python DB API 11839
- The standard DuckDB Python API provides a SQL interface compliant with the DB-API 2.0 specification described by PEP 249 similar to the SQLite Python API . Connection To use the module, you must first create a DuckDBPyConnection object that
...con.execute("CREATE TABLE answer AS SELECT 42 AS a") duckdb.set_default_connection(con) duckdb.sql("SELECT * FROM answer").fetchall() [(42,)] File-Based Connection If the database is a file path, a connection to a persistent database is established. If t...ecute() method of connections. Once a query has been executed, results can be retrieved using the fetchone , fetchmany and fetchall methods on the connection. fetchone() returns the next row, or None when no rows are left. fetchmany(size) returns a list...of at most size rows, one by default. fetchall() returns all remaining rows. df() and fetchnumpy() return the remaining rows as a pandas DataFrame or as NumPy arrays. Be... - https://man.mtool.work/duckdb/2.0/clients/python/dbapi.html
- Expression API 10466
- The Expression class represents an instance of an expression . Why Would I Use the Expression API? Use expressions to build filters and computed columns in Python. They are useful when column names or conditions depend on your code. import
..."hammer"], "price": [20, 42]}) price_column = "price" rel = duckdb.from_df(sales) print(rel.filter(col(price_column) > 30).fetchall()) [('hammer', 42)] An expression is passed to a method of a relation , such as select , filter , aggregate or sort . str(...explicit: rel = duckdb.sql("SELECT * FROM (VALUES ('x', 'y'), ('y', 'x')) t(s, x)") print(rel.filter(col("s") == col("x")).fetchall()) print(rel.filter(col("s") == duckdb.lit("x")).fetchall()) [] [('x', 'y')] When a plain string is also the name of a col...db.sql("SELECT {'a': 1} AS st, 2 AS \"st.a\"") print(rel.select(duckdb.col("st.a"), duckdb.col("st", "a"), col("st")["a"]).fetchall()) [(2, 1, 1)] Star Expression This expression selects all columns of the input source. Optionally it's possible to provid... - https://man.mtool.work/duckdb/2.0/clients/python/expression.html
- Data Ingestion 8664
- This page contains examples for data ingestion to Python using DuckDB. First, import the DuckDB package: import duckdb Then, proceed with any of the following sections. CSV Files CSV files can be read using the read_csv function, called eit
...d.DataFrame.from_dict({"i": [1, 2, 3, 4], "j": ["one", "two", "three", "four"]}) print(duckdb.sql("SELECT * FROM test_df").fetchall()) [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')] The same works for Pandas Series, Polars DataFrames, LazyFrames and...three", "four"]}) duckdb.register("test_df_view", my_dictionary["test_df"]) print(duckdb.sql("SELECT * FROM test_df_view").fetchall()) [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')] You can also create a table in DuckDB from the contents of the Data...stream__(requested_schema) obj = MyArrowStream(pa.table({"i": [1, 2, 3]})) print(duckdb.sql("SELECT sum(i) AS s FROM obj").fetchall()) print(duckdb.from_arrow(obj).fetchall()) [(6,)] [(1,), (2,), (3,)] Pandas DataFrames – object Columns pandas.DataFrame... - https://man.mtool.work/duckdb/2.0/clients/python/data_ingestion.html
- Conversion between DuckDB and Python 8493
- This page documents the rules for converting DuckDB results to Python and Python objects to DuckDB . Result Conversion: DuckDB Results to Python A result is read from a relation or, when using the DB-API / con.execute() , from the connectio
...relational methods return relations. Each has its own methods: Result Relation DB-API 2.0 ( con.execute() ) Python tuples fetchall() , iter_rows(batch_size=1024) fetchone() , fetchmany(size=1) , fetchall() Python dicts to_dicts() NumPy fetchnumpy() fetc...ss, i.e. it does not hold a result itself. To get specific rows of a result with the relational API you would use limit(n).fetchall() , iter_rows() or to_arrow_reader() instead. Note that with the DB-API, after a partial read with fetchone() or fetchmany...T con = duckdb.connect() print(con.execute("SELECT typeof(?), typeof(?), typeof(?)", [5, 2**64, duckdb.Value(5, TINYINT)]).fetchall()) [('INTEGER', 'HUGEINT', 'TINYINT')] float A float is always a DOUBLE . datetime.datetime For datetime we will check pan... - https://man.mtool.work/duckdb/2.0/clients/python/conversion.html
- Appender 8235
- Use an appender to insert rows that your Python code produces. It collects rows and writes them together in one SQL statement; this is called flushing. The with block below flushes on successful exit: import duckdb con = duckdb.connect() co
...ppend_row(1, "Mark") appender.append_rows([(2, "Hannes"), (3, "Gabor")]) print(con.sql("SELECT * FROM people ORDER BY id").fetchall()) [(1, 'Mark'), (2, 'Hannes'), (3, 'Gabor')] For data already in a DataFrame or Arrow table, INSERT INTO people SELECT *...action="delete", key=["sku"]) as appender: appender.append_row("gizmo") print(con.sql("SELECT * FROM stock ORDER BY sku").fetchall()) [('gadget', 0), ('widget', 10)] upsert runs an INSERT OR REPLACE , so the table needs exactly one primary key or unique...pend rows or call clear() while an execute() result is open, but must finish that result before calling flush() : call con.fetchall() , call con.fetchone() repeatedly until it returns None , or call con.complete() or con.abort() .... - https://man.mtool.work/duckdb/2.0/clients/python/appender.html
- PHP Client (PDO) 8235
- The PHP DuckDB PDO extension is a tertiary client and is maintained by a third-party. To use pdo_duckdb , follow the instructions below . The latest version of pdo_duckdb supports DuckDB 2.0.0. pdo_duckdb is a native DuckDB database driver
...ment->execute([1, 42.21, 'Hello DuckDB! ? ? ?']); $statement = $duckDb->query('SELECT * FROM table1'); print_r($statement->fetchAll(PDO::FETCH_ASSOC)); # Array # ( # [0] => Array # ( # [id] => 1 # [amount] => 42.21 # [description] => Hello DuckDB! ? ? ?...lose($fp); $db = new PDO('duckdb::memory:'); $statement = $db->query("SELECT * FROM '/tmp/test.csv'"); print_r($statement->fetchAll(PDO::FETCH_ASSOC)); # Array # ( # [0] => Array # ( # [aaa] => 123 # [bbb] => 456 # [ccc] => 789 # ) # [1] => Array # ( # [..._APPEND); $db = new PDO('duckdb::memory:'); $statement = $db->query("SELECT * FROM '/tmp/logs.json'"); print_r($statement->fetchAll(PDO::FETCH_ASSOC)); # Array # ( # [0] => Array # ( # [log] => log text # ) # [1] => Array # ( # [log] => log text 2 # ) #... - https://man.mtool.work/duckdb/2.0/clients/tertiary_clients/php_pdo.html
- Multiple Python Threads 8064
- This page demonstrates how to simultaneously insert into and read from a DuckDB database across multiple Python threads. This could be useful in scenarios where new data is flowing in and an analysis should be periodically re-run. Note that
...current_thread().name) result = local_con.execute(""" INSERT INTO my_inserts (thread_name) VALUES (?) """, (thread_name,)).fetchall() def read_from_thread(duckdb_con): # Create a DuckDB connection specifically for this thread local_con = duckdb_con.curso...LECT ? AS thread_name, count(*) AS row_counter, current_localtimestamp() AS read_time FROM my_inserts """, (thread_name,)).fetchall() print(results) Create Threads We define how many writers and readers to use, and define a list to track all of the threa... - https://man.mtool.work/duckdb/2.0/guides/python/multiple_threads.html
- Import from Numpy 7807
- It is possible to query Numpy arrays from DuckDB. There is no need to register the arrays manually – DuckDB can find them in the Python process by name thanks to replacement scans . For example: import duckdb import numpy as np columns = {
..."id": np.array([1, 2, 3]), "value": np.array([9.0, 8.0, 7.0]), } print(duckdb.sql("SELECT * FROM columns").fetchall()) [(1, 9.0), (2, 8.0), (3, 7.0)] Each array supplies one column. DuckDB also accepts a two-dimensional array, treating ea... - https://man.mtool.work/duckdb/2.0/guides/python/import_numpy.html
DuckDB 2.0 Documentation / man.mtool.work