diff --git a/config.go b/config.go index d1267621..2ec6ae3f 100644 --- a/config.go +++ b/config.go @@ -152,7 +152,7 @@ func ParseConfig(connString string) (*Config, error) { if connString != "" { // connString may be a database URL or a DSN - if strings.HasPrefix(connString, "postgres://") { + if strings.HasPrefix(connString, "postgres://") || strings.HasPrefix(connString, "postgresql://") { err := addURLSettings(settings, connString) if err != nil { return nil, &parseConfigError{connString: connString, msg: "failed to parse as URL", err: err} diff --git a/config_test.go b/config_test.go index af42094d..090302a2 100644 --- a/config_test.go +++ b/config_test.go @@ -214,6 +214,18 @@ func TestParseConfig(t *testing.T) { RuntimeParams: map[string]string{}, }, }, + { + name: "database url postgresql protocol", + connString: "postgresql://jack@localhost:5432/mydb?sslmode=disable", + config: &pgconn.Config{ + User: "jack", + Host: "localhost", + Port: 5432, + Database: "mydb", + TLSConfig: nil, + RuntimeParams: map[string]string{}, + }, + }, { name: "DSN everything", connString: "user=jack password=secret host=localhost port=5432 database=mydb sslmode=disable application_name=pgxtest search_path=myschema",