diff --git a/contrib/drivers/pgsql/pgsql_open.go b/contrib/drivers/pgsql/pgsql_open.go index 7bbd98462..21d3dce13 100644 --- a/contrib/drivers/pgsql/pgsql_open.go +++ b/contrib/drivers/pgsql/pgsql_open.go @@ -34,16 +34,12 @@ func (d *Driver) Open(config *gdb.ConfigNode) (db *sql.DB, err error) { source, _ = gregex.ReplaceString(`dbname=([\w\.\-]+)+`, "dbname="+config.Name, source) } } else { + source = fmt.Sprintf( + "user=%s password='%s' host=%s port=%s sslmode=disable", + config.User, config.Pass, config.Host, config.Port) + if config.Name != "" { - source = fmt.Sprintf( - "user=%s password=%s host=%s port=%s dbname=%s sslmode=disable", - config.User, config.Pass, config.Host, config.Port, config.Name, - ) - } else { - source = fmt.Sprintf( - "user=%s password=%s host=%s port=%s sslmode=disable", - config.User, config.Pass, config.Host, config.Port, - ) + source = fmt.Sprintf("%s dbname=%s", source, config.Name) } if config.Namespace != "" {