-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Array type default value doesnt work. PostgreSQL #1532
Comments
You can do: @Column("float4", {
array: true,
default: () => [ 0.0, 0.0, 0.0 ],
nullable: false
})
public testFloatArray: number[]; |
@pleerock your decision gives an error.
Query: ALTER TABLE "public"."test" ADD "testFloatArray" real array NOT NULL DEFAULT 0,0,0 |
default: "{0.0, 0.0, 0.0}", Works fine |
👍 |
If someone comes here to search for initializing empty array default: ()=>'array[]::integer[]' |
the '::' is cast syntax in postgres.
It might be redundant
…On Wed, Feb 6, 2019 at 5:25 AM Mitch Downey ***@***.***> wrote:
Could someone please explain why @thematan <https://github.com/thematan>'s
answer works, even when I am using a type of string[]? The integer[] part
doesn't make sense to me...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1532 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AL-7q5OsC3b35tjfIh78MP5JrNKX5Sw-ks5vKkssgaJpZM4RzkQy>
.
|
See typeorm/typeorm#1532, since simple-array is stored as text under the hood, we need to set the default for `events` to an empty string, rather than an empty array.
* 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 be unique * Make DateRange.title optional * Set default for DateRange.events to empty string See typeorm/typeorm#1532, since simple-array is stored as text under the hood, we need to set the default for `events` to an empty string, rather than an empty array. * Add cascades Set most cascades to ['insert', 'update'] to reduce risk of data loss if a single deletion causes a TON of data to be deleted. Exception: deleting a `Tag` deletes all the associated `Note`s.
@thematan what about for an array of type string? 'array[]::string[]' doesn't work 🤨 |
@joekendal Try this: default: () => 'array[]::text[]' |
While it's nice to have a workaround, it still feels like |
@pleerock please reopen this. I agree that |
any update on this ?
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 |
I will try to incorporate this into #7282, but could someone give me a few examples of the expected inputs/outputs? What happens if the array contains mixed types, nulls, etc? @gabimor default values defined as strings are treated as string values. You must use the |
I have submitted a PR with a couple of test cases that I would expect would work. If anyone has any others they'd like to add, I can add them to my PR. |
…7681) * fix: correctly strip type conversion in postgres for default values Use better regex to remove only type conversion, not the whole string to the end Closes: 7110 * fix: better regex * fix: modify postgres default regex to not break #1532 * fix: modify postgres default regex to support user-defined types This makes sure updated regex does not break migrations chnages introduced in #7647 * test: add test case for #5132
Has this reverted? I'm seeing this issue in v0.2.34 |
724d80b this commit was added to the method that i changed, and there's also a couple of commits tagged against this ticket. We're still using 0.2.32, so haven't seen the issue yet. |
Not working now:
|
Just in case it helps anyone...
|
what worked for us was:
|
For a text array default value, we had to account for whether a value in the array had any spaces. `'{${defaultValues.map((value) => (value.includes(" ") ? `"${value}"` : value)).join(",")}}'`; PostgreSQL will strip unnecessary |
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:
This generate query:
And i got an error:
error: malformed array literal: "[0,0,0]
The PostgresSQL syntax should be:
The text was updated successfully, but these errors were encountered: