Skip to content

Commit 062def9

Browse files
committed
add docs
1 parent e561be2 commit 062def9

1 file changed

Lines changed: 32 additions & 15 deletions

File tree

docsrc/Connecting_and_queries.rst

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ To get started, follow the steps below:
196196
) as connection:
197197
# Create a cursor
198198
cursor = connection.cursor()
199-
199+
200200
# Execute a simple test query
201201
cursor.execute("SELECT 1")
202202

203203
.. note::
204204

205-
Firebolt Core is assumed to be running locally on the default port (3473). For instructions
206-
on how to run Firebolt Core locally using Docker, refer to the
205+
Firebolt Core is assumed to be running locally on the default port (3473). For instructions
206+
on how to run Firebolt Core locally using Docker, refer to the
207207
`official docs <https://docs.firebolt.io/firebolt-core/firebolt-core-get-started>`_.
208208

209209

@@ -404,7 +404,7 @@ parameters equal in length to the number of placeholders in the statement.
404404
"INSERT INTO test_table2 VALUES ($1, $2, $3)",
405405
(2, "world", "2018-01-02"),
406406
)
407-
407+
408408
# paramstyle only needs to be set once, it will be used for all subsequent queries
409409

410410
cursor.execute(
@@ -444,11 +444,30 @@ For inserting large amounts of data more efficiently, you can use the ``bulk_ins
444444
with ``executemany()``. This concatenates multiple INSERT statements into a single batch request,
445445
which can significantly improve performance when inserting many rows.
446446

447-
**Note:** The ``bulk_insert`` parameter only works with INSERT statements and requires the
448-
``fb_numeric`` parameter style. Using it with other statement types or parameter styles will
447+
**Note:** The ``bulk_insert`` parameter only works with INSERT statements and supports both
448+
``fb_numeric`` and ``qmark`` parameter styles. Using it with other statement types will
449449
raise an error.
450450

451-
Example with FB_NUMERIC parameter style::
451+
**Example with QMARK parameter style (default):**
452+
453+
::
454+
455+
# Using the default qmark parameter style
456+
cursor.executemany(
457+
"INSERT INTO test_table VALUES (?, ?, ?)",
458+
(
459+
(1, "apple", "2019-01-01"),
460+
(2, "banana", "2020-01-01"),
461+
(3, "carrot", "2021-01-01"),
462+
(4, "donut", "2022-01-01"),
463+
(5, "eggplant", "2023-01-01")
464+
),
465+
bulk_insert=True # Enable bulk insert for better performance
466+
)
467+
468+
**Example with FB_NUMERIC parameter style:**
469+
470+
::
452471

453472
import firebolt.db
454473
# Set paramstyle to "fb_numeric" for server-side parameter substitution
@@ -463,11 +482,9 @@ Example with FB_NUMERIC parameter style::
463482
(4, "donut", "2022-01-01"),
464483
(5, "eggplant", "2023-01-01")
465484
),
466-
bulk_insert=True # Enable bulk insert for better performance (important-comment)
485+
bulk_insert=True # Enable bulk insert for better performance
467486
)
468487

469-
cursor.close()
470-
471488
When ``bulk_insert=True``, the SDK concatenates all INSERT statements into a single batch
472489
and sends them to the server for optimized batch processing.
473490

@@ -766,7 +783,7 @@ of execute_async is -1, which is the rowcount for queries where it's not applica
766783
cursor.execute_async("INSERT INTO my_table VALUES (5, 'egg', '2022-01-01')")
767784
token = cursor.async_query_token
768785

769-
Trying to access `async_query_token` before calling `execute_async` will raise an exception.
786+
Trying to access `async_query_token` before calling `execute_async` will raise an exception.
770787

771788
.. note::
772789
Multiple-statement queries are not supported for asynchronous queries. However, you can run each statement
@@ -781,9 +798,9 @@ Monitoring the query status
781798
To check the async query status you need to retrieve the token of the query. The token is a unique
782799
identifier for the query and can be used to fetch the query status. You can store this token
783800
outside of the current process and use it later to check the query status. :ref:`Connection <firebolt.db:Connection>` object
784-
has two methods to check the query status: :py:meth:`firebolt.db.connection.Connection.is_async_query_running` and
785-
:py:meth:`firebolt.db.connection.Connection.is_async_query_successful`.`is_async_query_running` will return True
786-
if the query is still running, and False otherwise. `is_async_query_successful` will return True if the query
801+
has two methods to check the query status: :py:meth:`firebolt.db.connection.Connection.is_async_query_running` and
802+
:py:meth:`firebolt.db.connection.Connection.is_async_query_successful`.`is_async_query_running` will return True
803+
if the query is still running, and False otherwise. `is_async_query_successful` will return True if the query
787804
has finished successfully, None if query is still running and False if the query has failed.
788805

789806
::
@@ -814,7 +831,7 @@ will send a cancel request to the server and the query will be stopped.
814831

815832
token = cursor.async_query_token
816833
connection.cancel_async_query(token)
817-
834+
818835
# Verify that the query was cancelled
819836
running = connection.is_async_query_running(token)
820837
print(running) # False

0 commit comments

Comments
 (0)