You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using pg-mem with a float4 column, inserting numeric values causes the error:
QueryFailedError: column "progress" is of type float4 but expression is of type text
Even though the query is correctly generated by TypeORM with numeric values, pg-mem treats these values as text during execution, leading to a type mismatch. In particular, the error occurs when float4 is registered in pg-mem and values are passed to the float4 column.
🐜 This seems to be an execution error, which means that your request syntax seems okay, but the resulting statement cannot be executed → Probably not a pg-mem error.
*️⃣ Failed SQL statement: INSERT INTO "task_assignments" ("progress") VALUES ('39'), ('79')
The TypeORM-generated query inserts numeric values as parameters, but pg-mem interprets them as text during execution, as shown in the error message where '39' and '79' are treated as strings.
Below is a minimal reproducible example that works on a real PostgreSQL instance but fails with pg-mem.
To Reproduce
CREATETABLEtask_assignments (
id serialPRIMARY KEY,
progress float4
);
INSERT INTO task_assignments (progress) VALUES (39), (79); -- This works on a real PostgreSQL instance
db.public.registerEquivalentType({name: 'float4',// which type is it equivalent to (will be able to cast it from it)equivalentTo: DataType.float,isValid(val: any){// Validate that the value is a valid numberreturntypeofval==='number'&&!isNaN(val);},});
Insert Data Using TypeORM:
constrepository=connection.getRepository(TaskAssignments);consttask1=newTaskAssignments();task1.progress=39;// Ensure progress is a numberawaitrepository.save(task1);consttask2=newTaskAssignments();task2.progress=79;// Another numeric valueawaitrepository.save(task2);
Despite the correct query and parameters, pg-mem interprets the values as text during execution, resulting in the error.
QueryFailedError: column "progress" is of type float4 but expression is of type text
🐜 This seems to be an execution error, which means that your request syntax seems okay,
but the resulting statement cannot be executed → Probably not a pg-mem error.
*️⃣ Failed SQL statement: INSERT INTO task_assignments (progress) VALUES ('39'), ('79');
pg-mem version
3.0.2
typeorm version
0.3.14
The text was updated successfully, but these errors were encountered:
Hi @oguimbal,
I’ve upgraded to pg-mem 3.0.3 and tested the issue again, but it seems the problem still persists. This time, I’m receiving a different error message:
QueryFailedError: invalid input syntax for type float4: 0
🐜 This seems to be an execution error, which means that your request syntax seems okay,
but the resulting statement cannot be executed → Probably not a pg-mem error.
However, the generated insert query for the float4 column is still treating the value as text, which may be contributing to the problem.
Describe the bug
When using pg-mem with a float4 column, inserting numeric values causes the error:
Even though the query is correctly generated by TypeORM with numeric values, pg-mem treats these values as text during execution, leading to a type mismatch. In particular, the error occurs when float4 is registered in pg-mem and values are passed to the float4 column.
The TypeORM-generated query inserts numeric values as parameters, but pg-mem interprets them as text during execution, as shown in the error message where '39' and '79' are treated as strings.
Below is a minimal reproducible example that works on a real PostgreSQL instance but fails with pg-mem.
To Reproduce
Code Example:
Despite the correct query and parameters, pg-mem interprets the values as text during execution, resulting in the error.
pg-mem version
3.0.2
typeorm version
0.3.14
The text was updated successfully, but these errors were encountered: