MCPcopy Create free account
hub / github.com/apecloud/myduckserver / VitessTypeToObjectID

Function VitessTypeToObjectID

pgserver/connection_data.go:125–184  ·  view source on GitHub ↗

VitessTypeToObjectID returns a type, as defined by Vitess, into a type as defined by Postgres. OIDs can be obtained with the following query: `SELECT oid, typname FROM pg_type ORDER BY 1;`

(typ query.Type)

Source from the content-addressed store, hash-verified

123}
124
125type PreparedStatementData struct {
126 Statement ConvertedStatement
127 ReturnFields []pgproto3.FieldDescription
128 BindVarTypes []uint32
129 Stmt *duckdb.Stmt
130 Closed *atomic.Bool
131}
132
133// VitessTypeToObjectID returns a type, as defined by Vitess, into a type as defined by Postgres.
134// OIDs can be obtained with the following query: `SELECT oid, typname FROM pg_type ORDER BY 1;`
135func VitessTypeToObjectID(typ query.Type) (uint32, error) {
136 switch typ {
137 case query.Type_INT8:
138 // Postgres doesn't make use of a small integer type for integer returns, which presents a bit of a conundrum.
139 // GMS defines boolean operations as the smallest integer type, while Postgres has an explicit bool type.
140 // We can't always assume that `INT8` means bool, since it could just be a small integer. As a result, we'll
141 // always return this as though it's an `INT16`, which also means that we can't support bools right now.
142 // OIDs 16 (bool) and 18 (char, ASCII only?) are the only single-byte types as far as I'm aware.
143 return uint32(oid.T_int2), nil
144 case query.Type_INT16:
145 // The technically correct OID is 21 (2-byte integer), however it seems like some clients don't actually expect
146 // this, so I'm not sure when it's actually used by Postgres. Because of this, we'll just pretend it's an `INT32`.
147 return uint32(oid.T_int2), nil
148 case query.Type_INT24:
149 // Postgres doesn't have a 3-byte integer type, so just pretend it's `INT32`.
150 return uint32(oid.T_int4), nil
151 case query.Type_INT32:
152 return uint32(oid.T_int4), nil
153 case query.Type_INT64:
154 return uint32(oid.T_int8), nil
155 case query.Type_UINT8:
156 return uint32(oid.T_int4), nil
157 case query.Type_UINT16:
158 return uint32(oid.T_int4), nil
159 case query.Type_UINT24:
160 return uint32(oid.T_int4), nil
161 case query.Type_UINT32:
162 // Since this has an upperbound greater than `INT32`, we'll treat it as `INT64`
163 return uint32(oid.T_oid), nil
164 case query.Type_UINT64:
165 // Since this has an upperbound greater than `INT64`, we'll treat it as `NUMERIC`
166 return uint32(oid.T_numeric), nil
167 case query.Type_FLOAT32:
168 return uint32(oid.T_float4), nil
169 case query.Type_FLOAT64:
170 return uint32(oid.T_float8), nil
171 case query.Type_DECIMAL:
172 return uint32(oid.T_numeric), nil
173 case query.Type_CHAR:
174 return uint32(oid.T_char), nil
175 case query.Type_VARCHAR:
176 return uint32(oid.T_varchar), nil
177 case query.Type_TEXT:
178 return uint32(oid.T_text), nil
179 case query.Type_BLOB:
180 return uint32(oid.T_bytea), nil
181 case query.Type_JSON:
182 return uint32(oid.T_json), nil

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected