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]: DatabaseErrorException: ERROR: column "due_date" is of type timestamp without time zone but expression is of type text; Hint: You will need to rewrite or cast the expression. #2232

Open
zackperdue opened this issue Apr 29, 2024 · 4 comments
Labels
bug Something isn't working driver/aws-data-api priority Will be worked on next qb/crud

Comments

@zackperdue
Copy link

What version of drizzle-orm are you using?

0.30.9

What version of drizzle-kit are you using?

0.20.17

Describe the Bug

I'm using pg adapter and RDSDataClient

When inserting a new record with a timestamp column, the query fails with the error:

DatabaseErrorException: ERROR: column "due_date" is of type timestamp without time zone but expression is of type text; Hint: You will need to rewrite or cast the expression.

Here is my schema with the timestamp column type:

Screenshot 2024-04-29 at 12 47 30 PM

Here is where I'm trying to insert the record:
Screenshot 2024-04-29 at 12 48 11 PM

Expected behavior

I expect the record to be saved with a properly formatted timestamp and not throw an error.

Environment & setup

local

@zackperdue zackperdue added the bug Something isn't working label Apr 29, 2024
@zackperdue
Copy link
Author

I've tried all permutations of the configuration, mode string, mode date, precision 3, with and without timezone, passing a date object and passing a string. Nothing seems to work.

@overlogic
Copy link

Looks like it is a duplicate of this bug #2097

@Steve2955
Copy link

Steve2955 commented Jul 29, 2024

Looks like it is a duplicate of this bug #2097

I also think so, they are very much related. Possible also even #1934. Sadly both issues are already closed, so for now it's probably worth keeping this open for visibility. I'm also facing a lot of similar issues with the typings in AWS Data Api queries using the latest versions of drizzle.

The issue seems to boil down to mergeQueries where the typings are set. Below is my proposed solution for it, which I also commented on the other issue.

Unfortunately, I'm lacking the ability to properly implement tests for this to create an PR here. It would be awesome if anyone of you could assist here.

function mergeQueries(queries: QueryWithTypings[]): QueryWithTypings {
	const result: QueryWithTypings = { sql: '', params: [] };
	for (const query of queries) {
		result.sql += query.sql;
		result.params.push(...query.params);
		if (query.typings?.length) {
			if (!result.typings) {
                                // setting an array of "none" for possible prior params 
                                // without typing resolves the issue for me:
				result.typings = new Array(result.params.length - query.params.length).fill("none");
			}
			result.typings.push(...query.typings);
		}
	}
	return result;
}

@Steve2955
Copy link

@zackperdue A possible workaround for you might be this:

{
  //...
  createdAt: sql`cast(${dayjs().utc().toDate()} as timestamp)`),
  //...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working driver/aws-data-api priority Will be worked on next qb/crud
Projects
None yet
Development

No branches or pull requests

4 participants