The client connection is then established. For how to write data and query data, please refer to [sample-program](https://docs.tdengine.com/cloud/connector/python/#sample-program).
The client connection is then established. For how to write data and query data, please refer to [sample-program](https://docs.tdengine.com/cloud/connector/python/#sample-program).
Application programs can execute `INSERT` statement through connectors to insert rows. The TAOS CLI can also be used to manually insert data.
## SQL Examples
Here are some brief examples for `INSET` statement. You can execute these statements manually by TDengine CLI or TDengine Cloud Explorer or programmatically by TDengine connectors.
For more details about `INSERT` please refer to [INSERT](/taos-sql/insert).
For more details about `INSERT` please refer to [INSERT](/taos-sql/insert).
:::info
- Inserting in batches can improve performance. Normally, the higher the batch size, the better the performance. Please note that a single row can't exceed 48K bytes and each SQL statement can't exceed 1MB.
- Inserting with multiple threads can also improve performance. However, depending on the system resources on the application side and the server side, when the number of inserting threads grows beyond a specific point the performance may drop instead of improving. The proper number of threads needs to be tested in a specific environment to find the best number.
:::
## Connector Examples
:::warning
<Tabs>
<TabItemvalue="python"label="Python">
- If the timestamp for the row to be inserted already exists in the table, the behavior depends on the value of parameter `UPDATE`. If it's set to 0 (the default value), the row will be discarded. If it's set to 1, the new values will override the old values for the same row.
In this example, we use `execute` method to execute SQL and get affected rows. The variable `conn` is an instance of class `taosrest.TaosRestConnection` we just created at [Connect Tutorial](./connect/python#connect).
- The timestamp to be inserted must be newer than the timestamp of subtracting current time by the parameter `KEEP`. If `KEEP` is set to 3650 days, then the data older than 3650 days ago can't be inserted. The timestamp to be inserted can't be newer than the timestamp of current time plus parameter `DAYS`. If `DAYS` is set to 2, the data newer than 2 days later can't be inserted.
SQL is used by TDengine as its query language. Application programs can send SQL statements to TDengine through REST API or connectors. TDengine's CLI `taos` can also be used to execute ad hoc SQL queries. Here is the list of major query functionalities supported by TDengine:
SQL is used by TDengine as its query language. Application programs can send SQL statements to TDengine through REST API or connectors. TDengine's CLI `taos` can also be used to execute ad hoc SQL queries. Here is the list of major query functionalities supported by TDengine:
...
@@ -113,3 +115,42 @@ Interpolation can be performed in TDengine if there is no data in a time range.
...
@@ -113,3 +115,42 @@ Interpolation can be performed in TDengine if there is no data in a time range.
For more details please refer to [Aggregate by Window](/taos-sql/interval).
For more details please refer to [Aggregate by Window](/taos-sql/interval).
## Connector Examples
<Tabs>
<TabItemvalue="python"label="Python">
In this example, we use `query` method to execute SQL and get a `result` object.
`taospy` is the official Python connector for TDengine. `taospy` wraps the [REST interface](/reference/rest-api) of TDengine. Additionally `taospy` provides a set of programming interfaces that conforms to the [Python Data Access Specification (PEP 249)](https://peps.python.org/pep-0249/). It is easy to integrate `taospy` with many third-party tools, such as [SQLAlchemy](https://www.sqlalchemy.org/) and [pandas](https://pandas.pydata.org/).
`taospy` is the official Python connector for TDengine. `taospy` wraps the [REST interface](/reference/rest-api) of TDengine. Additionally `taospy` provides a set of programming interfaces that conforms to the [Python Data Access Specification (PEP 249)](https://peps.python.org/pep-0249/). It is easy to integrate `taospy` with many third-party tools, such as [SQLAlchemy](https://www.sqlalchemy.org/) and [pandas](https://pandas.pydata.org/).
The source code for the Python connector is hosted on [GitHub](https://github.com/taosdata/taos-connector-python).
The source code for the Python connector is hosted on [GitHub](https://github.com/taosdata/taos-connector-python).
...
@@ -18,7 +17,12 @@ The source code for the Python connector is hosted on [GitHub](https://github.co
...
@@ -18,7 +17,12 @@ The source code for the Python connector is hosted on [GitHub](https://github.co
-`cursor.execute` : Used to execute arbitrary SQL statements.
-`cursor.execute` : Used to execute arbitrary SQL statements.
-`cursor.rowcount` : For write operations, returns the number of successful rows written. For query operations, returns the number of rows in the result set.
-`cursor.rowcount` : For write operations, returns the number of successful rows written. For query operations, returns the number of rows in the result set.
...
@@ -58,8 +68,8 @@ The ``TaosRestCursor`` class is an implementation of the PEP249 Cursor interface
...
@@ -58,8 +68,8 @@ The ``TaosRestCursor`` class is an implementation of the PEP249 Cursor interface
The `RestClient` class is a direct wrapper for the [REST API](/reference/rest-api). It contains only a `sql()` method for executing arbitrary SQL statements and returning the result.
The `RestClient` class is a direct wrapper for the [REST API](/reference/rest-api). It contains only a `sql()` method for executing arbitrary SQL statements and returning the result.