Skip to content

Commit 3a248e3

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

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
@@ -203,6 +203,7 @@ func NetworkAddress(host string, port uint16) (network, address string) {
203203
// PGAPPNAME
204204
// PGCONNECT_TIMEOUT
205205
// PGTARGETSESSIONATTRS
206+
// PGTZ
206207
//
207208
// See http://www.postgresql.org/docs/11/static/libpq-envars.html for details on the meaning of environment variables.
208209
//
@@ -457,6 +458,7 @@ func parseEnvSettings() map[string]string {
457458
"PGTARGETSESSIONATTRS": "target_session_attrs",
458459
"PGSERVICE": "service",
459460
"PGSERVICEFILE": "servicefile",
461+
"PGTZ": "timezone",
460462
}
461463

462464
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"}
935+
pgEnvvars := []string{"PGHOST", "PGPORT", "PGDATABASE", "PGUSER", "PGPASSWORD", "PGAPPNAME", "PGSSLMODE", "PGCONNECT_TIMEOUT", "PGSSLSNI", "PGTZ"}
936936

937937
tests := []struct {
938938
name string
@@ -971,6 +971,7 @@ func TestParseConfigEnvLibpq(t *testing.T) {
971971
"PGCONNECT_TIMEOUT": "10",
972972
"PGSSLMODE": "disable",
973973
"PGAPPNAME": "pgxtest",
974+
"PGTZ": "America/New_York",
974975
},
975976
config: &pgconn.Config{
976977
Host: "123.123.123.123",
@@ -980,7 +981,7 @@ func TestParseConfigEnvLibpq(t *testing.T) {
980981
Password: "baz",
981982
ConnectTimeout: 10 * time.Second,
982983
TLSConfig: nil,
983-
RuntimeParams: map[string]string{"application_name": "pgxtest"},
984+
RuntimeParams: map[string]string{"application_name": "pgxtest", "timezone": "America/New_York"},
984985
},
985986
},
986987
{

0 commit comments

Comments
 (0)