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

Postgres not serialize byte[] on insert and update #527

Closed
el-gato-de-nieve opened this issue Dec 1, 2022 · 4 comments
Closed

Postgres not serialize byte[] on insert and update #527

el-gato-de-nieve opened this issue Dec 1, 2022 · 4 comments

Comments

@el-gato-de-nieve
Copy link

It works properly if we need to insert/update bytea
but on arrays is fails with error
column "columname" is of type bytea[] but expression is of type bytea

@porsager
Copy link
Owner

porsager commented Feb 1, 2023

Should be fixed in #392

@porsager porsager closed this as completed Feb 1, 2023
@sfalihi
Copy link

sfalihi commented Nov 22, 2024

unfortianatly not woking testing in version 3.4.4

my error is : column "body" is of type bytea[] but expression is of type bytea
log of my variable is : [ Buffer(39) [ 200, 184, 239, 112, 67, 3, 21, 40, 135, 197, 105, 221, 114, 115, 46, 218, 200, 40, 214, 82, 66, 98, 117, 233, 200, 71, 2, 221, 254, 114, 205, 58, 248, 28, 10, 124, 161, 172, 18 ] ]
and when i try to insert it like below error shown:
sqlinsert into .. values (${variable}) ...

@porsager
Copy link
Owner

Right - your buffer is inside an array. shows clearly in the log you just pasted.

@sfalihi
Copy link

sfalihi commented Nov 22, 2024

after so many attempts this solution works perfectly with correctly scaping also:

sqlINSERT ... VALUES(ARRAY[${yourBufferArray.reduce( (acc, curr, index) => index === 0 ? sql${curr} : sql${acc}, ${curr} )}]::bytea[]);

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

3 participants