0
votes

My table has these columns:

priority double precision DEFAULT 0.5::double precision, 
created_at timestamp without time zone DEFAULT now(),

But for the record that was just inserted the value is null:

enter image description here

Why doesn't it work?

Update: I've updated the flask-sqlalchemy row to:

priority = db.Column(db.Float, server_default=u'0.5', nullable=False)

and the table shows:

priority double precision NOT NULL DEFAULT 0.5::double precision,

but now it gives the error:

sqlalchemy.exc.IntegrityError: (psycopg2.IntegrityError) null value in column "priority" violates not-null constraint

1
Presumably, your client process explicitly sent a NULL. How are you doing the insert?Nick Barnes
Please show us the complete Insert statement you are using. And you probably do not want double, for details see: floating-point-gui.dea_horse_with_no_name

1 Answers

0
votes

In the database add a NOT NULL constraint to the column. So you will notice when the client try to insert a null value:

priority double precision DEFAULT 0.5::double precision NOT NULL, 

In the client use the keyword DEFAULT instead of null when doing insert:

INSERT INTO your_table (priority, created) VALUES (DEFAULT, DEFAULT);

See the official documentation for more info: http://www.postgresql.org/docs/9.3/static/sql-insert.html