diff --git a/pkg/sql/pgwire/command_result.go b/pkg/sql/pgwire/command_result.go index 6f8cc87fdba4..21745d92e11d 100644 --- a/pkg/sql/pgwire/command_result.go +++ b/pkg/sql/pgwire/command_result.go @@ -219,7 +219,7 @@ func (r *commandResult) SetColumns(ctx context.Context, cols sqlbase.ResultColum } r.oids = make([]oid.Oid, len(cols)) for i, col := range cols { - r.oids[i] = mapResultOid(col.Typ.Oid()) + r.oids[i] = col.Typ.Oid() } } diff --git a/pkg/sql/pgwire/conn.go b/pkg/sql/pgwire/conn.go index 2eec76c4534d..41c43054b54b 100644 --- a/pkg/sql/pgwire/conn.go +++ b/pkg/sql/pgwire/conn.go @@ -1277,7 +1277,7 @@ func (c *conn) writeRowDescription( typ := pgTypeForParserType(column.Typ) c.msgBuilder.putInt32(int32(column.TableID)) // Table OID (optional). c.msgBuilder.putInt16(int16(column.PGAttributeNum)) // Column attribute ID (optional). - c.msgBuilder.putInt32(int32(mapResultOid(typ.oid))) + c.msgBuilder.putInt32(int32(typ.oid)) c.msgBuilder.putInt16(int16(typ.size)) c.msgBuilder.putInt32(column.GetTypeModifier()) // Type modifier if formatCodes == nil { diff --git a/pkg/sql/pgwire/testdata/pgtest/row_description b/pkg/sql/pgwire/testdata/pgtest/row_description index bbc17498835d..3bd3ed8d74a9 100644 --- a/pkg/sql/pgwire/testdata/pgtest/row_description +++ b/pkg/sql/pgwire/testdata/pgtest/row_description @@ -115,7 +115,47 @@ Query {"String": "SELECT b FROM tab3"} until ReadyForQuery ---- -{"Type":"RowDescription","Fields":[{"Name":"b","TableOID":58,"TableAttributeNumber":2,"DataTypeOID":25,"DataTypeSize":-1,"TypeModifier":12,"Format":0}]} +{"Type":"RowDescription","Fields":[{"Name":"b","TableOID":58,"TableAttributeNumber":2,"DataTypeOID":1042,"DataTypeSize":-1,"TypeModifier":12,"Format":0}]} {"Type":"DataRow","Values":[{"text":"hello"}]} {"Type":"CommandComplete","CommandTag":"SELECT 1"} {"Type":"ReadyForQuery","TxStatus":"I"} + +# tab4 is a regression test for #51360 +send +Query {"String": "CREATE TABLE tab4 (a INT8 PRIMARY KEY, b VARCHAR(256)[] NOT NULL)"} +---- + +until +ReadyForQuery +---- +{"Type":"CommandComplete","CommandTag":"CREATE TABLE"} +{"Type":"ReadyForQuery","TxStatus":"I"} + +send +Query {"String": "INSERT INTO tab4 VALUES(4, ARRAY['hello', 'goodbye'])"} +---- + +until +ReadyForQuery +---- +{"Type":"CommandComplete","CommandTag":"INSERT 0 1"} +{"Type":"ReadyForQuery","TxStatus":"I"} + +# 80 = ASCII 'P' for Portal +send +Parse {"Name": "s", "Query": "SELECT b FROM tab4"} +Bind {"DestinationPortal": "p", "PreparedStatement": "s"} +Describe {"ObjectType": 80, "Name": "p"} +Execute {"Portal": "p"} +Sync +---- + +until +ReadyForQuery +---- +{"Type":"ParseComplete"} +{"Type":"BindComplete"} +{"Type":"RowDescription","Fields":[{"Name":"b","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":1015,"DataTypeSize":-1,"TypeModifier":-1,"Format":0}]} +{"Type":"DataRow","Values":[{"text":"{hello,goodbye}"}]} +{"Type":"CommandComplete","CommandTag":"SELECT 1"} +{"Type":"ReadyForQuery","TxStatus":"I"} diff --git a/pkg/sql/pgwire/types.go b/pkg/sql/pgwire/types.go index b3734078e09e..d789ba411153 100644 --- a/pkg/sql/pgwire/types.go +++ b/pkg/sql/pgwire/types.go @@ -64,30 +64,6 @@ func pgTypeForParserType(t *types.T) pgType { } } -var resultOidMap = map[oid.Oid]oid.Oid{ - oid.T_bit: oid.T_varbit, - oid.T__bit: oid.T__varbit, - oid.T_bpchar: oid.T_text, - oid.T__bpchar: oid.T__text, - oid.T_char: oid.T_text, - oid.T__char: oid.T__text, - oid.T_varchar: oid.T_text, - oid.T__varchar: oid.T__text, -} - -// mapResultOid maps an Oid value returned by the server to an Oid value that is -// backwards-compatible with previous versions of CRDB. See this issue for more -// details: https://github.com/cockroachdb/cockroach/issues/36811 -// -// TODO(andyk): Remove this once issue #36811 is resolved. -func mapResultOid(o oid.Oid) oid.Oid { - mapped := resultOidMap[o] - if mapped != 0 { - return mapped - } - return o -} - func (b *writeBuffer) writeTextDatum( ctx context.Context, d tree.Datum, conv sessiondata.DataConversionConfig, ) { diff --git a/pkg/testutils/pgtest/datadriven.go b/pkg/testutils/pgtest/datadriven.go index 267048934309..8fd972cfde07 100644 --- a/pkg/testutils/pgtest/datadriven.go +++ b/pkg/testutils/pgtest/datadriven.go @@ -162,6 +162,8 @@ func toMessage(typ string) interface{} { return &pgproto3.CommandComplete{} case "DataRow": return &pgproto3.DataRow{} + case "Describe": + return &pgproto3.Describe{} case "ErrorResponse": return &pgproto3.ErrorResponse{} case "Execute":