Pg: insert/update boolean type field with false value

Created on 17 Apr 2017  路  2Comments  路  Source: go-pg/pg

How do I INSERT / UPDATE false value into a field with boolean type?
When I'm setting corresponding ORM-structure field to 'fase', result query translate it to NULL.
Example:

``type TSDBMProxy struct {
tableName struct{}
Id int64
Available bool}

psdbmProxy.Available = true
sResult, err = Db.Model(psdbmProxy).
Column("available").
Update()
``

results in query:
UPDATE proxy AS tsdbm_proxy SET "available" = NULL WHERE tsdbm_proxy."id" = 3

How do I overcome the issue?

Most helpful comment

This is such a confusing behaviour.

I had the same problem, but my column declaration was:

active boolean default true not null,

And inserting a struct with Active: false would produce a SQL insert with active = TRUE.
Now setting the sql:",notnull" tag fixes the problem, but it's not clear why it was required in the first place.

All 2 comments

Add sql:",notnull" tag to the struct field.

This is such a confusing behaviour.

I had the same problem, but my column declaration was:

active boolean default true not null,

And inserting a struct with Active: false would produce a SQL insert with active = TRUE.
Now setting the sql:",notnull" tag fixes the problem, but it's not clear why it was required in the first place.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rhymes picture rhymes  路  5Comments

pahanini picture pahanini  路  4Comments

willsr picture willsr  路  5Comments

AbooJan picture AbooJan  路  5Comments

RepentantGopher picture RepentantGopher  路  5Comments