convex-backend icon indicating copy to clipboard operation
convex-backend copied to clipboard

Import | Import numbers as string if the schema is v.string()

Open mmailaender opened this issue 5 months ago • 2 comments

I have the following csv

"accountNumber","accountName" "0001","reserviert" "0040","reserviert"

accountNumber is v.string() in convex (to preserver the leading 0), so importing via npx convex import --table accounts accounts.csv fails because the importer tries to import accountNumber as v.number.

Failed to insert or update a document in table "accounts" because it does not match the schema: Value does not match validator.
Path: .accountNumber
Value: 1.0
Validator: v.string()

So instead I would expect that the importer tries to cast the values to the format of the field. Or at least treat everything as string and if the target field is of type v.number try to cast the string to number.

mmailaender avatar Jul 04 '25 10:07 mmailaender

https://docs.convex.dev/database/import-export/import#single-table-import is the spec for the behavior.

Seems like there may be a bug here where the string is being interpreted as a number. You can work around it by using the json format.

nipunn1313 avatar Jul 07 '25 23:07 nipunn1313

Thanks for the report.

nipunn1313 avatar Jul 07 '25 23:07 nipunn1313