Skip to content

Commit 3442c8a

Browse files
committed
Fixed issues 2546 and 2548
1 parent 98153b0 commit 3442c8a

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

server/config/parameters_list.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3556,6 +3556,24 @@ var postgresConfigParameters = map[string]sql.SystemVariable{
35563556
if err == nil {
35573557
return v, true
35583558
}
3559+
for _, layout := range []string{
3560+
"-07",
3561+
"-0700",
3562+
"-070000",
3563+
"-07:00",
3564+
"-07:00:00",
3565+
"UTC-07",
3566+
"UTC-0700",
3567+
"UTC-070000",
3568+
"UTC-07:00",
3569+
"UTC-07:00:00",
3570+
"MST",
3571+
} {
3572+
parsed, err := time.Parse(layout, v)
3573+
if err == nil {
3574+
return parsed.Format("-07:00:00"), true
3575+
}
3576+
}
35593577
return nil, false
35603578
}
35613579
}

server/doltgres_handler.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,20 @@ func schemaToFieldDescriptions(ctx *sql.Context, s sql.Schema, formatCodes []int
507507
var typmod = int32(-1)
508508

509509
var err error
510+
colName := c.Name
511+
dataTypeSize := int16(c.Type.MaxTextResponseByteLength(ctx))
512+
tableAttributeNumber := uint16(i + 1) // TODO: this should be based on the actual table field index, not the return schema
510513
if doltgresType, ok := c.Type.(*pgtypes.DoltgresType); ok {
514+
if doltgresType.ID == pgtypes.Unknown.ID {
515+
// It appears that the `unknown` type is always converted to `text` on output since they're binary
516+
// coercible. There are other assumptions that we can make as well, as no function or column will return
517+
// the `unknown` type, so we can infer that this is a raw value being returned as-is from the query,
518+
// such as `SELECT 'foo';`
519+
doltgresType = pgtypes.Text
520+
dataTypeSize = int16(doltgresType.MaxTextResponseByteLength(ctx))
521+
colName = "?column?"
522+
tableAttributeNumber = 0
523+
}
511524
if doltgresType.TypType == pgtypes.TypeType_Domain {
512525
oid = id.Cache().ToOID(doltgresType.BaseTypeID.AsId())
513526
} else {
@@ -522,11 +535,11 @@ func schemaToFieldDescriptions(ctx *sql.Context, s sql.Schema, formatCodes []int
522535
}
523536

524537
fields[i] = pgproto3.FieldDescription{
525-
Name: []byte(c.Name),
538+
Name: []byte(colName),
526539
TableOID: uint32(0),
527-
TableAttributeNumber: uint16(i + 1), // TODO: this should be based on the actual table field index, not the return schema
540+
TableAttributeNumber: tableAttributeNumber,
528541
DataTypeOID: oid,
529-
DataTypeSize: int16(c.Type.MaxTextResponseByteLength(ctx)),
542+
DataTypeSize: dataTypeSize,
530543
TypeModifier: typmod,
531544
Format: formatCodes[i],
532545
}

testing/go/issues_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,5 +407,33 @@ limit 1`,
407407
},
408408
},
409409
},
410+
{
411+
Name: "Issue #2548",
412+
SetUpScript: []string{
413+
"CREATE TABLE test (pk INT4 PRIMARY KEY, v1 TIMESTAMP WITH TIME ZONE);",
414+
},
415+
Assertions: []ScriptTestAssertion{
416+
{
417+
Query: `SET TimeZone = 'UTC-01:00';`,
418+
Expected: []sql.Row{},
419+
},
420+
{
421+
Query: `INSERT INTO test VALUES (1, '2026-04-15 10:11:12');`,
422+
Expected: []sql.Row{},
423+
},
424+
{
425+
Query: `SET TimeZone = 'UTC-03:00';`,
426+
Expected: []sql.Row{},
427+
},
428+
{
429+
Query: `INSERT INTO test VALUES (2, '2026-04-15 10:11:12');`,
430+
Expected: []sql.Row{},
431+
},
432+
{
433+
Query: `SELECT (SELECT v1 FROM test WHERE pk = 2) - (SELECT v1 FROM test WHERE pk = 1);`,
434+
Expected: []sql.Row{{"-02:00:00"}},
435+
},
436+
},
437+
},
410438
})
411439
}

testing/go/wire_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5186,6 +5186,34 @@ func TestWireTypesSending(t *testing.T) {
51865186
},
51875187
},
51885188
},
5189+
{ // https://github.com/dolthub/doltgresql/issues/2546
5190+
Name: "Issue #2546",
5191+
Assertions: []WireScriptTestAssertion{
5192+
{
5193+
Send: []pgproto3.FrontendMessage{
5194+
&pgproto3.Query{String: "SELECT 'foo';"},
5195+
},
5196+
Receive: []pgproto3.BackendMessage{
5197+
&pgproto3.RowDescription{
5198+
Fields: []pgproto3.FieldDescription{
5199+
{
5200+
Name: []byte("?column?"),
5201+
TableOID: 0,
5202+
TableAttributeNumber: 0,
5203+
DataTypeOID: 25,
5204+
DataTypeSize: -1,
5205+
TypeModifier: -1,
5206+
Format: 0,
5207+
},
5208+
},
5209+
},
5210+
&pgproto3.DataRow{Values: [][]byte{[]byte("foo")}},
5211+
&pgproto3.CommandComplete{CommandTag: []byte("SELECT 1")},
5212+
&pgproto3.ReadyForQuery{TxStatus: 'I'},
5213+
},
5214+
},
5215+
},
5216+
},
51895217
})
51905218
}
51915219

0 commit comments

Comments
 (0)