How to set a default value for a column ?

81 views
Skip to first unread message

Vicky

unread,
Mar 24, 2017, 7:51:20 AM3/24/17
to lovefield-users
Is there a way to set a default value for a column when we create a table ?

I know that by default every column type has its own default value. But can we change it ?

Arthur Hsu

unread,
Mar 24, 2017, 12:48:09 PM3/24/17
to lovefield-users
I don't believe this is a common SQL feature. You can fork and implement it yourself if you need it.

dpa...@chromium.org

unread,
Mar 24, 2017, 3:29:33 PM3/24/17
to lovefield-users
You can also use a db.update() query to update all the columns to a new default value, after you get a connection to the DB.

db.update(myTable).
    set(order.column, newDefaultValue).
    where(order.column.eq(previousDefaultValue)).
    exec();


On Friday, March 24, 2017 at 4:51:20 AM UTC-7, Vicky wrote:

dpa...@chromium.org

unread,
Mar 24, 2017, 3:30:53 PM3/24/17
to lovefield-users
Correction

db.update(myTable).
   
set(myTable.column, newDefaultValue).
   
where(myTable.column.eq(previousDefaultValue)).
   
exec();

thusi...@gmail.com

unread,
Dec 5, 2019, 6:21:16 AM12/5/19
to lovefield-users

When we update records according to the above update query we always see the following error message in the console.


Error: http://google.github.io/lovefield/error_lookup/src/error_lookup.html?c=501


Please advise on any clue on how to resolve this.

Arthur Hsu

unread,
Dec 5, 2019, 1:19:14 PM12/5/19
to lovefield-users
Error message said "Value is not bounded". Seems to me that your "newDefaultValue" is created by lf.bind and you did not bind proper value on it.

https://github.com/google/lovefield/blob/master/docs/spec/04_query.md#45-parameterized-query has information regarding how to do proper binding on parameterized query.

thusi...@gmail.com

unread,
Dec 5, 2019, 10:39:49 PM12/5/19
to lovefield-users

lovefield_update_error.jpg


var q = db.
update(p).
set(p._mode, lf.bind(1)).
where(p.seq.eq(lf.bind(0)));

q.bind([2, 1]).exec();


For the above simple update code we get the error message. But the strange thing is insert, delete and select expressions works without any issue.

Error message is not descriptive enough for us to dig deeper. Is it a DB lock sort of a thing? This is very critical for us to solve this issue.

Thanks.
Thusitha
Reply all
Reply to author
Forward
0 new messages