Skip to content

Commit

Permalink
Merge pull request cockroachdb#7664 from nvanbenschoten/nvanbenschote…
Browse files Browse the repository at this point in the history
…n/decodeOidDatumTSTZ

sql/pgwire: Support TimestampTZ in decodeOidDatum
  • Loading branch information
nvanbenschoten authored Jul 7, 2016
2 parents 8ce5a00 + 3b63f30 commit ee996f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 12 additions & 1 deletion sql/pgwire/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ func decodeOidDatum(id oid.Oid, code formatCode, b []byte) (parser.Datum, error)
default:
return d, errors.Errorf("unsupported bytea format code: %s", code)
}
case oid.T_timestamp, oid.T_timestamptz:
case oid.T_timestamp:
switch code {
case formatText:
ts, err := parseTs(string(b))
Expand All @@ -611,6 +611,17 @@ func decodeOidDatum(id oid.Oid, code formatCode, b []byte) (parser.Datum, error)
default:
return d, errors.Errorf("unsupported timestamp format code: %s", code)
}
case oid.T_timestamptz:
switch code {
case formatText:
ts, err := parseTs(string(b))
if err != nil {
return d, errors.Errorf("could not parse string %q as timestamp", b)
}
d = parser.MakeDTimestampTZ(ts, time.Microsecond)
default:
return d, errors.Errorf("unsupported timestamptz format code: %s", code)
}
case oid.T_date:
switch code {
case formatText:
Expand Down
3 changes: 1 addition & 2 deletions sql/pgwire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,7 @@ func TestPGPreparedExec(t *testing.T) {
},
},
{
// TODO(dt, nvanbenschoten): can we avoid this cast? #7647
"INSERT INTO d.types VALUES ($1, $2, $3, $4, $5, $6, $7::timestamptz, $8, $9, $10)",
"INSERT INTO d.types VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
[]preparedExecTest{
base.RowsAffected(1).SetArgs(
int64(0),
Expand Down

0 comments on commit ee996f9

Please sign in to comment.