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

Query errors with riverdatabasesql, Bun, and pgdriver #655

Open
NathanBaulch opened this issue Oct 24, 2024 · 4 comments
Open

Query errors with riverdatabasesql, Bun, and pgdriver #655

NathanBaulch opened this issue Oct 24, 2024 · 4 comments

Comments

@NathanBaulch
Copy link
Contributor

I'm completely new to River and immediately ran into the following issue when playing with the examples against Pg 16.4:

msg="Elector: Error attempting to elect" err="ERROR: cannot cast type bigint to interval (SQLSTATE=42846)"

The offending LeaderAttemptElect SQL is attempting to cast an integer time.Duration parameter into a Pg interval which is not allowed. Weird that nobody else appears to have hit the same issue, I wonder where I've gone wrong!?

Anyway, I'm currently working around this by patching all 4 instances of now() + $2 in the river source with now() + make_interval(secs => $2), as recommended in this issue: sqlc-dev/sqlc#429 (comment)

@bgentry
Copy link
Contributor

bgentry commented Oct 24, 2024

@NathanBaulch I’m not sure how this could have slipped past our testing 🤔 can you confirm that you’re using the dbsql driver, as well as the underlying db driver you’re using (pgx or other)?

@NathanBaulch
Copy link
Contributor Author

OK, that was a bit of a rabbit hole but it turns out the bun sql driver my project uses doesn't prepare statements before execution (for alleged perf reasons). That step is required in order to infer that the @ttl parameter should be interpreted as an interval (oid 1186), otherwise the underlying int64 is used.

Is there any interest in supporting non-prepare-ing drivers? I'd be happy to send a PR that replaces ::interval with make_interval(...).

@bgentry
Copy link
Contributor

bgentry commented Oct 25, 2024

Ah, it seems like you're using Bun's own pgdriver which I don't think we've tried, so it seems likely to be an issue specific to that. We have a fair bit of test coverage for the drivers including the LeaderAttemptElect query, but that uses pgx under the hood via its stdlib database/sql package.

Have you tried Bun with pgx, or is that not an option for some reason?

@bgentry bgentry changed the title cannot cast type bigint to interval Query errors with riverdatabasesql, Bun, and pgdriver Oct 25, 2024
@NathanBaulch
Copy link
Contributor Author

I've switched to pgx for now, hopefully no side effects in my project! I guess this issue can serve as a warning to other Bun users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants