Skip to content

Commit 540fcaa

Browse files
committed
Add support for PGOPTIONS environment variable
Match libpq behavior for PGOPTIONS environment variable. See https://www.postgresql.org/docs/current/libpq-envars.html
1 parent 3a248e3 commit 540fcaa

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

pgconn/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ func NetworkAddress(host string, port uint16) (network, address string) {
200200
// PGSSLKEY
201201
// PGSSLROOTCERT
202202
// PGSSLPASSWORD
203+
// PGOPTIONS
203204
// PGAPPNAME
204205
// PGCONNECT_TIMEOUT
205206
// PGTARGETSESSIONATTRS
@@ -459,6 +460,7 @@ func parseEnvSettings() map[string]string {
459460
"PGSERVICE": "service",
460461
"PGSERVICEFILE": "servicefile",
461462
"PGTZ": "timezone",
463+
"PGOPTIONS": "options",
462464
}
463465

464466
for envname, realname := range nameMap {

pgconn/config_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ func TestParseConfigEnvLibpq(t *testing.T) {
932932
}
933933
}
934934

935-
pgEnvvars := []string{"PGHOST", "PGPORT", "PGDATABASE", "PGUSER", "PGPASSWORD", "PGAPPNAME", "PGSSLMODE", "PGCONNECT_TIMEOUT", "PGSSLSNI", "PGTZ"}
935+
pgEnvvars := []string{"PGHOST", "PGPORT", "PGDATABASE", "PGUSER", "PGPASSWORD", "PGAPPNAME", "PGSSLMODE", "PGCONNECT_TIMEOUT", "PGSSLSNI", "PGTZ", "PGOPTIONS"}
936936

937937
tests := []struct {
938938
name string
@@ -972,6 +972,7 @@ func TestParseConfigEnvLibpq(t *testing.T) {
972972
"PGSSLMODE": "disable",
973973
"PGAPPNAME": "pgxtest",
974974
"PGTZ": "America/New_York",
975+
"PGOPTIONS": "-c search_path=myschema",
975976
},
976977
config: &pgconn.Config{
977978
Host: "123.123.123.123",
@@ -981,7 +982,7 @@ func TestParseConfigEnvLibpq(t *testing.T) {
981982
Password: "baz",
982983
ConnectTimeout: 10 * time.Second,
983984
TLSConfig: nil,
984-
RuntimeParams: map[string]string{"application_name": "pgxtest", "timezone": "America/New_York"},
985+
RuntimeParams: map[string]string{"application_name": "pgxtest", "timezone": "America/New_York", "options": "-c search_path=myschema"},
985986
},
986987
},
987988
{

0 commit comments

Comments
 (0)