2

I am creating a database migration using Knex (v0.19.5) and PostgreSQL (v10.1) but when I try to set the default value to a TEXT array column it gives me a malformed array literal error.

table.specificType('test', 'TEXT[]').defaultTo(['foo', 'bar']);

This is the error message

Array value must start with "{" or dimension information.

error: malformed array literal: "foo,bar"

Maybe I am missing something but I can't get it to work and I can't find anything useful in their official docs.

2 Answers 2

5

I finally solved it by simply setting the array into a literal string.

table.specificType('test', 'TEXT[]').defaultTo('{\'\'foo\'\',\'\'bar\'\'}');
0

Another solution is to use pg.raw('...')

table.specificType("test", "text[]").defaultTo(pg.raw(`'{}'::text[]`))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.