Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: querying on postgres interval type returns PostgresInterval, not string as inferred. #1542

Closed
zolboo-gtn opened this issue Nov 22, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@zolboo-gtn
Copy link

zolboo-gtn commented Nov 22, 2023

What version of drizzle-orm are you using?

0.29.0

What version of drizzle-kit are you using?

0.20.4

Describe the Bug

const attendance = pgTable(
  "attendance",
  {
    ...
    breaktime: interval("breaktime"),
    ...
  }
);

Querying above table returns

type Attendance = {
    ...
    breaktime: PostgresInterval;
    ...
}

not inferred type

type Attendance = {
    ...
    breaktime: string | null;
    ...
}

I tried setting intervalstyle as iso_8601 on the table, but had no effect.

Expected behavior

Above setup returns string, something like P1Y2M3DT4H5M6S.

Environment & setup

No response

@zolboo-gtn zolboo-gtn added the bug Something isn't working label Nov 22, 2023
@zolboo-gtn
Copy link
Author

above problem occurs on

db.query.attendance.findMany({
    ...
})

but not on

db.query.user.findMany({
    ...
    with: {
        attendances: true
    },
})

Second query returns somethings like PT15M as expected.

@realmikesolo
Copy link
Collaborator

Hello, @zolboo-gtn! Do you use neon driver?

@AndriiSherman
Copy link
Member

should be fixed in 0.30.7

@n3oney
Copy link

n3oney commented Apr 19, 2024

I still get this issue, on 0.30.8 with neon driver

@realmikesolo
Copy link
Collaborator

Hey, @n3oney! You might use neon-http, right?

@n3oney
Copy link

n3oney commented Apr 19, 2024

Yep, neon-http.
Currently did this to fight the type errors:

  withdrawalFrequency: interval("withdrawal_frequency", {
    fields: "day",
  })
    .$type<{ days: number }>()
    .notNull()
    .default(sql`(INTERVAL '7 days')`),

@realmikesolo
Copy link
Collaborator

Got it @n3oney. It was fixed only for neon-serverless. Will be fixed for neon-http soon.

@san4d
Copy link

san4d commented Apr 21, 2024

I'm still experiencing this issue on on drizzle-orm 0.30.9 and neon serverless 0.9.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants