drizzle-team / drizzle-team/drizzle-orm

[BUG]: drizzle-kit introspection emits unknown() for PostgreSQL bytea without importing it; drizzle-orm 0.45.x has no unknown export

Open
#5,941 0 comments 0 reactions 0 assignees View on GitHub
bug bug/fixed-in-beta
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

*(Related but distinct: [#5184](https://github.com/drizzle-team/drizzle-orm/issues/5184) — `bytea` documented but missing from stable package; [#3902](https://github.com/drizzle-team/drizzle-orm/issues/3902) — introspection emits `unknown()` for `bytea`)*.

### What version of `drizzle-orm` are you using?

0.45.2

### What version of `drizzle-kit` are you using?

0.31.10

### Other packages

_No response_

### Describe the Bug

**Undesired behavior**

Running `drizzle-kit pull` against a PostgreSQL database with `bytea` columns produces a `schema.ts` that calls `unknown("column_name")` but does **not** import `unknown` from `drizzle-orm/pg-core`. Importing that schema at runtime fails immediately:

```
ReferenceError: unknown is not defined
at drizzle/schema.ts:385:14
```

Generated output looks like:

```ts
import { pgTable, integer, /* ... */ } from "drizzle-orm/pg-core"
// no `unknown` import

export const assertion = pgTable("assertion", {
store: text().notNull(),
authorizationModelId: text("authorization_model_id").notNull(),
// TODO: failed to parse database type 'bytea'
assertions: unknown("assertions"),
});
```

On `drizzle-orm@0.45.2`, `unknown` is also **not exported** from `drizzle-orm/pg-core`, so even adding the import would not fix it without a manual workaround.

**Steps to reproduce**

1. PostgreSQL database with tables containing `bytea` columns (e.g. OpenFGA tables: `assertion`, `authorization_model`, `tuple`, `changelog`).
2. `drizzle.config.ts`:
```ts
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
dialect: 'postgresql',
dbCredentials: { url: process.env.DATABASE_URL! },
});
```
3. Run `drizzle-kit pull`.
4. Import the generated schema in application code, e.g.:
```ts
import { fhirIdentityMuParams } from './drizzle/schema';
```
5. Run the app (`bun ./main.ts`).

**Desired result**

One of:

- PostgreSQL introspection maps `bytea` to a supported column type (e.g. `bytea()` per [docs](https://orm.drizzle.team/docs/column-types/pg)), **or**
- If `unknown()` is intentional for unsupported types, drizzle-kit should add `unknown` to the generated imports **and** drizzle-orm should export `unknown` from `pg-core`.

**Additional context**

- **Database:** PostgreSQL (local Docker, port 5433).
- **Driver:** `drizzle-orm/bun-sql` (Bun built-in SQL).
- **Root cause (drizzle-kit):** PostgreSQL column generator (`column9` in `bin.cjs`) has no `bytea` branch; it falls through to `unknown("…")` without adding `unknown` to `imports.pg`. EdgeDB path handles `bytea` via `bytes()`.
- **Workaround:** Define a local helper before generated tables:
```ts
const unknown = customType<{ data: unknown }>({
dataType() { return "bytea"; },
});
```
This is fragile — re-running `pull` overwrites manual edits unless the helper is kept outside the generated file.

**Suggested fix**

1. Add `bytea` handling to PostgreSQL introspection (mirror EdgeDB’s `bytes()` path), **or** export `unknown` from `drizzle-orm/pg-core` and include it in generated imports when used.
2. Align stable `0.45.x` with docs: [bytea is documented](https://orm.drizzle.team/docs/column-types/pg) but not present in `drizzle-orm@0.45.2` (see [#5184](https://github.com/drizzle-team/drizzle-orm/issues/5184)).

---

Thanks

Contributor guide

Open the contributing guide

Research direction

Start with the PostgreSQL column generator (`column9` in `bin.cjs`), its `imports.pg` handling, and the EdgeDB `bytes()` path described in the report. Verify how `bytea` is generated and imported, then check the stable `drizzle-orm@0.45.2` pg-core exports; done means generated schemas handle bytea without a runtime ReferenceError.

Written by the indexing model from the issue text.

Assessment

Tech stack
bun, postgresql, typescript
Domain
databases, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.