docs-v2/content/v2.0/reference/flux/stdlib/sql/to.md

1.4 KiB

title description aliases menu weight
sql.to() function The `sql.to()` function writes data to a SQL database.
/v2.0/reference/flux/functions/sql/to/
v2_0_ref
name parent
sql.to SQL
202

The sql.to() function writes data to a SQL database.

Function type: Output

import "sql"

sql.to(
  driverName: "mysql",
  dataSourceName: "username:password@tcp(localhost:3306)/dbname?param=value",
  table: "ExampleTable"
)

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

table

The destination table.

Data type: String

Examples

Write data to a MySQL database

import "sql"

sql.to(
  driverName: "mysql",
  dataSourceName: "user:password@tcp(localhost:3306)/db",
  table: "ExampleTable"
)

Write data to a Postgres database

import "sql"

sql.to(
  driverName: "postgres",
  dataSourceName: "postgresql://user:password@localhost",
  table: "ExampleTable"
)