MCPcopy Create free account
hub / github.com/bytebase/bytebase / getVersion

Method getVersion

backend/plugin/db/pg/pg.go:357–378  ·  view source on GitHub ↗

getVersion gets the version of Postgres server.

(ctx context.Context)

Source from the content-addressed store, hash-verified

355
356// getVersion gets the version of Postgres server.
357func (d *Driver) getVersion(ctx context.Context) (string, error) {
358 // SHOW server_version_num returns an integer such as 100005, which means 10.0.5.
359 // It is more convenient to use SHOW server_version to get the version string.
360 // PostgreSQL supports it since 8.2.
361 // https://www.postgresql.org/docs/current/functions-info.html
362 query := "SHOW server_version_num"
363 var version string
364 if err := d.db.QueryRowContext(ctx, query).Scan(&version); err != nil {
365 if err == sql.ErrNoRows {
366 return "", common.FormatDBErrorEmptyRowWithQuery(query)
367 }
368 return "", util.FormatErrorWithQuery(err, query)
369 }
370 versionNum, err := strconv.Atoi(version)
371 if err != nil {
372 return "", err
373 }
374 // https://www.postgresql.org/docs/current/libpq-status.html#LIBPQ-PQSERVERVERSION
375 // Convert to semantic version.
376 major, minor, patch := versionNum/1_00_00, (versionNum/100)%100, versionNum%100
377 return fmt.Sprintf("%d.%d.%d", major, minor, patch), nil
378}
379
380// Execute will execute the statement. For CREATE DATABASE statement, some types of databases such as Postgres
381// will not use transactions to execute the statement but will still use transactions to execute the rest of statements.

Callers 2

SyncInstanceMethod · 0.95
SyncDBSchemaMethod · 0.95

Implementers 15

MockDriverbackend/plugin/advisor/utils_for_tests
Driverbackend/plugin/db/bigquery/bigquery.go
Driverbackend/plugin/db/mongodb/mongodb.go
Driverbackend/plugin/db/trino/trino.go
Driverbackend/plugin/db/redshift/redshift.go
Driverbackend/plugin/db/oracle/oracle.go
Driverbackend/plugin/db/dynamodb/dynamodb.go
Driverbackend/plugin/db/cosmosdb/cosmosdb.go
Driverbackend/plugin/db/spanner/spanner.go
Driverbackend/plugin/db/mssql/mssql.go
Driverbackend/plugin/db/mysql/mysql.go
Driverbackend/plugin/db/pg/pg.go

Calls 3

FormatErrorWithQueryFunction · 0.92
ScanMethod · 0.80

Tested by

no test coverage detected