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

Function InferSchema

pgtypes/pgtypes.go:294–331  ·  view source on GitHub ↗
(rows *stdsql.Rows)

Source from the content-addressed store, hash-verified

292 return nil, 0, 0, fallback, fmt.Errorf("unsupported type %s", name)
293 }
294 return
295}
296
297func InferSchema(rows *stdsql.Rows) (sql.Schema, error) {
298 types, err := rows.ColumnTypes()
299 if err != nil {
300 return nil, err
301 }
302
303 schema := make(sql.Schema, len(types))
304 for i, t := range types {
305 pgType, precision, scale, fallback, err := GoDuckDBTypeNameToPostgresType(t.DatabaseTypeName())
306 if err != nil {
307 return nil, err
308 }
309 nullable, _ := t.Nullable()
310
311 switch pgType.OID {
312 case pgtype.NumericOID, pgtype.NumericArrayOID:
313 // Currently, ok is always false
314 if p, s, ok := t.DecimalSize(); ok {
315 precision = int32(p)
316 scale = int32(s)
317 }
318 }
319
320 schema[i] = &sql.Column{
321 Name: t.Name(),
322 Type: PostgresType{
323 PG: pgType,
324 Size: PostgresTypeSize(pgType.OID),
325 Precision: precision,
326 Scale: scale,
327 Fallback: fallback,
328 },
329 Nullable: nullable,
330 }
331 }
332
333 return schema, nil
334}

Callers 3

ComPrepareParsedMethod · 0.92
executeQueryMethod · 0.92
executeBoundPlanMethod · 0.92

Calls 3

PostgresTypeSizeFunction · 0.85
NameMethod · 0.45

Tested by

no test coverage detected