{"record":{"id":"a00c85f5bf16a603","repo":"cube-js/cube","slug":"unable-to-detect-type-for-field-f-name-with-d","errorCode":null,"errorMessage":"Unable to detect type for field \"${f.name}\" with dataTypeID: ${f.dataTypeID}","messagePattern":"Unable to detect type for field \"(.+?)\" with dataTypeID: (.+?)","errorType":"exception","errorClass":"PostgresError","httpStatus":null,"severity":"error","filePath":"packages/cubejs-postgres-driver/src/PostgresDriver.ts","lineNumber":357,"sourceCode":"  }\n\n  protected async prepareConnection(\n    conn: PgClient,\n    options: { executionTimeout: number } = {\n      executionTimeout: this.config.executionTimeout ? <number>(this.config.executionTimeout) * 1000 : 600000\n    }\n  ) {\n    await conn.query(`SET TIME ZONE '${this.config.storeTimezone || 'UTC'}'`);\n    await conn.query(`SET statement_timeout TO ${options.executionTimeout}`);\n\n    await this.loadUserDefinedTypes(conn);\n  }\n\n  protected mapFields(fields: FieldDef[]) {\n    return fields.map((f) => {\n      const postgresType = this.getPostgresTypeForField(f.dataTypeID);\n      if (!postgresType) {\n        throw new PostgresError(\n          `Unable to detect type for field \"${f.name}\" with dataTypeID: ${f.dataTypeID}`\n        );\n      }\n\n      return ({\n        name: f.name,\n        type: this.toGenericType(postgresType)\n      });\n    });\n  }\n\n  public async stream(\n    query: string,\n    values: unknown[],\n    { highWaterMark }: StreamOptions\n  ): Promise<StreamTableDataWithTypes> {\n    PostgresDriver.checkValuesLimit(values);\n","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-postgres-driver/src/PostgresDriver.ts#L339-L375","documentation":"PostgresDriver.mapFields maps pg result field OIDs (dataTypeID) to Cube types via getPostgresTypeForField. When the OID is unknown to the driver's type map, it cannot determine the column type and throws a PostgresError naming the field and OID.","triggerScenarios":"`stream` or `downloadQueryResults` returns result fields whose dataTypeID is not in the driver's OID→type map — typically custom/composite/enum types or rarely used native types.","commonSituations":"Selecting custom enum or user-defined types in the query; Postgres extension types (e.g., hstore, geometry via older drivers); casting omissions in generated SQL after schema changes.","solutions":["Cast the offending column to a standard type in the SQL: `col::text` (or ::int8, ::float8, etc.).","Add the missing OID mapping if extending the driver (getPostgresTypeForField map).","Update the data model so the member uses a base type rather than a custom type.","Check driver/Postgres version mismatch — new built-in types may be unknown to older pg OIDs handled by the driver."],"exampleFix":"// before\nSELECT status FROM orders; -- status is a custom enum, dataTypeID unmapped\n// after\nSELECT status::text AS status FROM orders;","handlingStrategy":"validation","validationCode":"// ensure selected columns are cast to base types\nconst KNOWN_OIDS = new Set([16, 20, 21, 23, 25, 700, 701, 1043, 1082, 1114, 1184, 1700]);\nfor (const f of fields) {\n  if (!KNOWN_OIDS.has(f.dataTypeID)) console.warn(`Cast ${f.name} (OID ${f.dataTypeID}) to a base type`);\n}","typeGuard":"function hasKnownType(f: FieldDef): boolean {\n  return !!driver.getPostgresTypeForField(f.dataTypeID); // or check OID map\n}","tryCatchPattern":"try {\n  const res = await driver.downloadQueryResults(query);\n} catch (e) {\n  if (e.message.includes('Unable to detect type for field')) {\n    console.error(`Add a cast (::text, ::int8, ...) for ${e.message.match(/field \"(.*?)\"/)?.[1]}`);\n  }\n  throw e;\n}","preventionTips":["Cast custom enums/composites to ::text or base types in SQL.","Avoid selecting extension types (hstore, geometry) in Cube queries.","Keep driver versions current to cover newer built-in type OIDs.","Add pre-flight queries verifying member types in staging."],"tags":["postgres","type-mapping","oid","result-parsing"],"backgroundTag":"unknown-column-type","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}