Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions server/config/parameters_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3556,6 +3556,24 @@ var postgresConfigParameters = map[string]sql.SystemVariable{
if err == nil {
return v, true
}
for _, layout := range []string{
Comment thread
Hydrocharged marked this conversation as resolved.
"-07",
"-0700",
"-070000",
"-07:00",
"-07:00:00",
"UTC-07",
"UTC-0700",
"UTC-070000",
"UTC-07:00",
"UTC-07:00:00",
"MST",
} {
parsed, err := time.Parse(layout, v)
if err == nil {
return parsed.Format("-07:00:00"), true
}
}
return nil, false
}
}
Expand Down
19 changes: 16 additions & 3 deletions server/doltgres_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,20 @@ func schemaToFieldDescriptions(ctx *sql.Context, s sql.Schema, formatCodes []int
var typmod = int32(-1)

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

fields[i] = pgproto3.FieldDescription{
Name: []byte(c.Name),
Name: []byte(colName),
TableOID: uint32(0),
TableAttributeNumber: uint16(i + 1), // TODO: this should be based on the actual table field index, not the return schema
TableAttributeNumber: tableAttributeNumber,
DataTypeOID: oid,
DataTypeSize: int16(c.Type.MaxTextResponseByteLength(ctx)),
DataTypeSize: dataTypeSize,
TypeModifier: typmod,
Format: formatCodes[i],
}
Expand Down
28 changes: 28 additions & 0 deletions testing/go/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,5 +407,33 @@ limit 1`,
},
},
},
{
Name: "Issue #2548",
SetUpScript: []string{
"CREATE TABLE test (pk INT4 PRIMARY KEY, v1 TIMESTAMP WITH TIME ZONE);",
},
Assertions: []ScriptTestAssertion{
Comment thread
Hydrocharged marked this conversation as resolved.
{
Query: `SET TimeZone = 'UTC-01:00';`,
Expected: []sql.Row{},
},
{
Query: `INSERT INTO test VALUES (1, '2026-04-15 10:11:12');`,
Expected: []sql.Row{},
},
{
Query: `SET TimeZone = 'UTC-03:00';`,
Expected: []sql.Row{},
},
{
Query: `INSERT INTO test VALUES (2, '2026-04-15 10:11:12');`,
Expected: []sql.Row{},
},
{
Query: `SELECT (SELECT v1 FROM test WHERE pk = 2) - (SELECT v1 FROM test WHERE pk = 1);`,
Expected: []sql.Row{{"-02:00:00"}},
},
},
},
})
}
28 changes: 28 additions & 0 deletions testing/go/wire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5186,6 +5186,34 @@ func TestWireTypesSending(t *testing.T) {
},
},
},
{ // https://github.com/dolthub/doltgresql/issues/2546
Name: "Issue #2546",
Assertions: []WireScriptTestAssertion{
{
Send: []pgproto3.FrontendMessage{
&pgproto3.Query{String: "SELECT 'foo';"},
},
Receive: []pgproto3.BackendMessage{
&pgproto3.RowDescription{
Fields: []pgproto3.FieldDescription{
{
Name: []byte("?column?"),
TableOID: 0,
TableAttributeNumber: 0,
DataTypeOID: 25,
DataTypeSize: -1,
TypeModifier: -1,
Format: 0,
},
},
},
&pgproto3.DataRow{Values: [][]byte{[]byte("foo")}},
&pgproto3.CommandComplete{CommandTag: []byte("SELECT 1")},
&pgproto3.ReadyForQuery{TxStatus: 'I'},
},
},
},
},
})
}

Expand Down
Loading