Robert Brax Robert Brax - 1 year ago 102
Javascript Question

Set postgres array field to null from javascript

I'm updating a field in a postgres database, and I need to set this field to empty that is default NULL for these kind of field.

Here is the query and the field that I try to set to null is link_target_language

UPDATE links SET link_target_language = null WHERE unique_id = 'b06457b8'

null here won't work because any array field requires {}:

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

But if I put {} then the field in the db is {} not NULL as true empty fields.

So how to truly empty an array field in postgress from UPDATE command with js ?

Answer Source

Cast null to the array type:

set link_target_language = null::text[]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download