typeorm: Array type default value doesnt work. PostgreSQL
Issue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] websql
TypeORM version:
[ ] latest
[x] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem: My entity column:
@Column("float4", {
array: true,
default: [ 0.0, 0.0, 0.0 ],
nullable: false
})
public testFloatArray: number[];
This generate query:
ALTER TABLE "public"."test" ADD "testFloatArray" real array NOT NULL DEFAULT '[0,0,0]'
And i got an error: error: malformed array literal: "[0,0,0]
The PostgresSQL syntax should be:
ALTER TABLE "public"."test" ADD "testFloatArray" real array NOT NULL DEFAULT '{0,0,0}'
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (6 by maintainers)
Commits related to this issue
- Set default for DateRange.events to empty string See https://github.com/typeorm/typeorm/issues/1532, since simple-array is stored as text under the hood, we need to set the default for `events` to an... — committed to bobbywang000/nemosyne by bobbywang000 4 years ago
- Update db schemas (#4) * Add Uniqueness Constraints for DateRange, Entry, Tag DateRange: start/end dates have to be unique Entry: written date and subject date have to be unique Tag: name has to... — committed to bobbywang000/nemosyne by bobbywang000 4 years ago
- fix: modify postgres default regex to not break #1532 — committed to kauz/typeorm by kauz 3 years ago
- fix: correctly strip type conversion in postgres for default values (#7681) * fix: correctly strip type conversion in postgres for default values Use better regex to remove only type conversion, n... — committed to typeorm/typeorm by kauz 3 years ago
While it’s nice to have a workaround, it still feels like
default: []
should work and this should be open.@pleerock please reopen this. I agree that
default: []
should work, it’s super intuitive.Hi @thematan. Typeorm from version 0.2.12 support define default enum array as array of typescript enum https://github.com/typeorm/typeorm/pull/3414:
Works fine
If someone comes here to search for initializing empty array this works:
default: ()=>‘array[]::integer[]’
any update on this ? We have a thing with our migrations regarding this. Our column:
and although the column is creted on the DB just fine, the migrations are keep being generated for this column like so:
we have to manually delete them from the migration file each time, it’s frustrating.
We tried also
default: '{}'
,default: 'ARRAY[]'
nothing works. the column migration keep being generated each timeYou can do:
Just in case it helps anyone… This seems to work for me, setting the default as an empty string when using
simple-array
type:@joekendal Try this:
@pleerock your decision gives an error. Error:
Query: