An issue when creating string[] elements
I'm getting an error:
DatabaseErrorException: ERROR: column "images" is of type text[] but expression is of type text; Hint: You will need to rewrite or cast the expression.
For the following code:
I'm using aws rds data api
31 Replies
This is the schema
@Angelelz
@solo
Hi, @Vision2023! Do you use Aurora PostgreSQL or just PostgreSQL?
Aurora Postgresql
Can you show the resulting SQL query? You can pass
logger: true
to the options when instantiating the DB object@Angelelz
@solo any ideas why?
@Vision2023 I am testing with aws-data api now. With
postgres-js
driver everything worksThats weird. Lemme try executing raw sql in drizzle
I get same error with this:
@Vision2023
your query:
postgres-js
aws-data-api
also, I executed this and it worked out:
Please whats ur schema like. Maybe its my schema
This is mine @solo
schemas are the samew, I think problem is here
because when I execute raw query as an example above, everything works out, but when we use query builder and then log query, we can see, that there is
:1
instead of $1
. In postgres-js
you can see this difference
So, there is no problem with images
in your schema
You can create github issue for that or I can do it if you wantOk so the problem is :1 instead of $1?
I'm really sorry but I dont really get the issue
Maybe the issue lies with the rds data api or sth
Your query doesn't seem right to me. Seems like you're passing a jsonb object? Console log the objects you are inserting. That might be your problem
I am sorry, I was wrong about
:1
, but I don't understand now what cause the problem
SQL Query:
Ok
I just realised the issue is prolly because of rds data api because when I was using postgres-js driver, it was working
@Vision2023 +, I wrote about it above, but I'm curious whether the problem lies with the Drizzle AWS Data API package or with the RDS Data API.
We're running into this issue too 😦
@solo Its an issue with rds data api
Lack of support for arrays.
However, theres a workaround tho
Manually casting the field as an array(text[] in my case) in the query
Like
@kieranmch do u have any workarounds?
@solo Thinking of making a lil update to do this automatically for data api in drizzle-orm.
I dont think the pr would be accepted tho but at least I can use the fork in my project.
Wdyt
BTW Source: https://github.com/koxudaxi/local-data-api#how-to-insert-array-data-into-postgresql
GitHub
GitHub - koxudaxi/local-data-api: Data API for local, you can write...
Data API for local, you can write unittest for AWS Aurora Serverless's Data API - GitHub - koxudaxi/local-data-api: Data API for local, you can write unittest for AWS Aurora Serverless&am...
@Vision2023 I think you are right, that issue is with rds fata api.
parameters: Array parameters are not supported.
https://docs.aws.amazon.com/rdsdataservice/latest/APIReference/API_ExecuteStatement.html#API_ExecuteStatement_RequestBody
Also, you can try another workaround, cast js array to postgres array and then pass it to your query:
ExecuteStatement - RDS Data API
Runs a SQL statement against a database.
ok
btw, you can create an issue on github (enhancement tag) for this
Ok
Will do
We tried the raw SQL solution and it broke the typeHint feature in a horrendous way, the types all ended up getting shifted along one and mismatched with the values
Like it was submitting 7 values but only 6 types
So what did u end up with @kieranmch
@solo @Angelelz This change works for me. Wdyt about it
In
drizzle-orm/src/aws-data-api/pg/driver.ts
@solo @Angelelz Created an issue https://github.com/drizzle-team/drizzle-orm/issues/1912 and pull request https://github.com/drizzle-team/drizzle-orm/pull/1911
GitHub
[FEATURE]: Add support for inserting and updating arrays in aws-dat...
Describe what you want Currently in drizzle, if you want to insert or update an array, there is a typing issue like this: DatabaseErrorException: ERROR: column "images" is of type text[] ...
GitHub
[Pg] Add insert/update array support in aws-data-api by livingforj...
Currently in drizzle, if you want to insert or update an array, there is a typing issue like this:
DatabaseErrorException: ERROR: column "images" is of type text[] but expression is of ty...
@Vision2023 Sorry for the late response. If it works, then that's great. It is cool that you've also created tests for it. The Drizzle team will check it as needed or if the opportunity arises.
@Andrew Sherman is it possible to get a timeline on how long it'll take sth like this to be reviewed and potentially merged in