Postgres synchronisation unnecessarily drops column with data type "float"
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.5
Postgres v10
Steps to reproduce or a small repository showing the problem:
Create an Entity with a column of data type float:
@Entity()
export class FloatTest{
@PrimaryColumn()
id: number
@Column('float')
some_num: number
}
Add some data to the table:
const con = await createConnection({
...,
synchronize: true,
logging: true
})
await con.manager.save(FloatTest, { id: 0, sum_num: 10.51 })
On the initial run this all works fine – run it again however and you’ll get an error like the following: column "some_num" contains null values
. With logging enabled the “sum_num” column is clearly being dropped and rebuilt.
I think this error is due to Postgres using double precision
as float
internally(see https://www.postgresql.org/docs/10/static/datatype-numeric.html section 8.1.3). This seems to be the case when the column check SQL is run: SELECT *, "udt_name"::"regtype" AS "regtype" FROM "information_schema"."columns"...
. The “regtype” for the float data type returns double precision.
The solution, I think is to add an additional check in the normalizeType
function in PostgresDriver.ts
like so:
else if (column.type === "float") {
return "double precision";
}
Thanks for the great ORM!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:10 (4 by maintainers)
Confirming this bug on
typeorm@next
version@serranoarevalo Yep, just use the
double precision
type instead offloat
when defining your column. Or modify the source to add the extra conditional statement(see the very end of my original post)