SAP HANA Database Client for Go
Go-hdb is a native Go (Golang) HANA database driver for Go's database/sql package. It implements the "SAP HANA SQL Command Network Protocol" directly, so it is pure Go with no cgo and no HANA client library dependency — a single statically linked binary, cross-compilable, with driver upgrades decoupled from the database version.
For the official SAP HANA client Go support (not this database driver), please see SAP Help Portal.
go get -u github.com/SAP/go-hdb/driverpackage main
import (
"database/sql"
"fmt"
"github.com/SAP/go-hdb/driver"
)
func main() {
connector := driver.NewBasicAuthConnector("host:port", "user", "password")
db := sql.OpenDB(connector)
defer db.Close()
var name string
if err := db.QueryRow("select current_user from dummy").Scan(&name); err != nil {
panic(err)
}
fmt.Println(name)
}To build go-hdb, a working Go environment of the latest or second latest Go version is required.
API documentation and documented examples can be found at .
The HANA cloud connection proxy uses SNI, which requires a TLS connection. By default, one can rely on the root certificate set provided by the host, which already comes with the necessary DigiCert certificates (CA, G5). For more information on Go TLS certificate handling, please see https://pkg.go.dev/crypto/tls#Config.
Assuming the HANA cloud 'endpoint' is "something.hanacloud.ondemand.com:443", the DSN should look as follows:
"hdb://:@something.hanacloud.ondemand.com:443?TLSServerName=something.hanacloud.ondemand.com"where:
If a specific root certificate (e.g. self-signed) is needed, the TLSRootCAFile DSN parameter must point to the location in the file system where the root certificate file in PEM format is stored.
To run the driver integration tests, a HANA Database server is required. The test user must have privileges to create database schemas.
Set the environment variable GOHDBDSN:
#linux example
export GOHDBDSN="hdb://user:password@host:port"
go testUsing the Go build tag 'unit', only the driver unit tests will be executed (no HANA Database server required):
go test --tags unitIntegration tests include network I/O which dominates wall time and obscures driver CPU cost. To profile only the driver code, collect a CPU profile and then filter out database-tagged samples with tagignore=db:
go test -v -test.cpuprofile cpu.out
go tool pprof cpu.out(pprof) tagignore=db
(pprof) top 10The tagignore=db filter excludes samples tagged with database activity (network, syscalls waiting on the server), leaving only driver-side CPU work visible. To further exclude CESU-8 encoding/decoding overhead, add tagignore=cesu8:
(pprof) tagignore=db,cesu8
(pprof) top 10SAP SE or an SAP affiliate company and go-hdb contributors. Please see our LICENSE for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available via the REUSE tool.
This project integrates AI into its development practices; contributors are expected to review and take ownership of all AI-assisted changes. Its design philosophy and development guidelines are documented in AGENTS.md.
No open issues yet, or sync has not completed.