drizzle-team / drizzle-team/drizzle-orm

[BUG]: PostgresError: malformed array literal: "{date_trunc('month'::text, "eventAt")}"

Open
#5,055 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.

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

0.44.7

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

0.30.5

### Other packages

drizzle-zod@0.5.1

### Describe the Bug

**Defined index**

```ts
// col definition
eventAt: timestamp('eventAt').notNull().defaultNow(),

// index definition
index('usage_item_eventAt_month_idx').on(sql.raw('date_trunc(\'month\', "eventAt")')),
```

**Expected behavior**

* The indexes should be read from PG DB correctly

**Current behavior**

* The index was written to PG DB correctly on `db:push` (1st time call)
* Reading index data from PG DB fails on `db:push` (2nd time call)

```> drizzle-kit push --verbose

No config path provided, using default 'drizzle.config.ts'
Reading config file '/Users/pavel/Projects/delta-one-nextjs/drizzle.config.ts'
Using 'postgres' driver for database querying
[⡿] Pulling schema from database...
node:internal/process/promises:391
triggerUncaughtException(err, true /* fromPromise */);
^

PostgresError: malformed array literal: "{date_trunc('month'::text, "eventAt")}"
at ErrorResponse (file:///Users/pavel/Projects/delta-one-nextjs/node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/src/connection.js:788:26)
at handle (file:///Users/pavel/Projects/delta-one-nextjs/node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/src/connection.js:474:6)
at Socket.data (file:///Users/pavel/Projects/delta-one-nextjs/node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:524:28)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at TCP.onStreamRead (node:internal/stream_base_commons:191:23) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '22P02',
detail: 'Unexpected array element.',
file: 'arrayfuncs.c',
line: '672',
routine: 'ArrayCount'
}

Node.js v20.19.4

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.