sql.from() function
The sql.from()
function retrieves data from a SQL data source.
Function type: Input
import "sql"
sql.from(
driverName: "postgres",
dataSourceName: "postgresql://user:password@localhost",
query:"SELECT * FROM TestTable"
)
Parameters
driverName
The driver used to connect to the SQL database.
Data type: String
The following drivers are available:
- mysql
- postgres
dataSourceName
The connection string used to connect to the SQL database. The string’s form and structure depend on the driver used.
Data type: String
Driver dataSourceName examples
# Postgres Driver:
postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full
# MySQL Driver:
username:password@tcp(localhost:3306)/dbname?param=value
query
The query to run against the SQL database.
Data type: String
Examples
Query a MySQL database
import "sql"
sql.from(
driverName: "mysql",
dataSourceName: "user:password@tcp(localhost:3306)/db",
query:"SELECT * FROM ExampleTable"
)
Query a Postgres database
import "sql"
sql.from(
driverName: "postgres",
dataSourceName: "postgresql://user:password@localhost",
query:"SELECT * FROM ExampleTable"
)
Bug Reports and Feedback
Thank you for being willing to help test InfluxDB v2.0 alpha! Feedback and bug reports are welcome and encouraged both for InfluxDB and this documentation. Submit feedback using one of the following methods:
- Post in the InfluxData Community
- In the InfluxDB UI, click Feedback in the left navigation bar.
- Submit documentation issues to the InfluxDB 2.0 documentation repository.
- Submit InfluxDB issues to the InfluxDB repository.