[SQLObject] Default value

Hi,
I have a field in a PostgreSQL database table for which I would like the
database to calculate the default value. The field itself is declared as
NOT NULL DEFAULT (some function)
When defining the SQLObject class, if I use
field = Col()
and then try to create an item I get the error that the field must have
a value.
If I use instead:
field = Col(default=None)
I am not required to give a value but it is translated into INSERT ...
SET FIELD VALUE NULL, which is not allowed by the table definition.
How can I make SQLObject create an INSERT statement without the field
'FIELD' so that the database will take over the calculation of the
default value? It wouldn't make sense to duplicate the database logic of
default value calculation in Python to be used in Col(default = ...)
Your help is appreciated.
Hong Yuan

Thread view

Hi,
I have a field in a PostgreSQL database table for which I would like the
database to calculate the default value. The field itself is declared as
NOT NULL DEFAULT (some function)
When defining the SQLObject class, if I use
field = Col()
and then try to create an item I get the error that the field must have
a value.
If I use instead:
field = Col(default=None)
I am not required to give a value but it is translated into INSERT ...
SET FIELD VALUE NULL, which is not allowed by the table definition.
How can I make SQLObject create an INSERT statement without the field
'FIELD' so that the database will take over the calculation of the
default value? It wouldn't make sense to duplicate the database logic of
default value calculation in Python to be used in Col(default = ...)
Your help is appreciated.
Hong Yuan

On Fri, Dec 24, 2004 at 05:33:54PM +0800, Hong Yuan wrote:
> I have a field in a PostgreSQL database table for which I would like the
> database to calculate the default value.
SQLObject cannot do it yet.
Oleg.
--
Oleg Broytmann http://phd.pp.ru/ phd@...
Programmers don't die, they just GOSUB without RETURN.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hong Yuan wrote:
| Hi,
|
| I have a field in a PostgreSQL database table for which I would like the
| database to calculate the default value. The field itself is declared as
| NOT NULL DEFAULT (some function)
| I am not required to give a value but it is translated into INSERT ...
| SET FIELD VALUE NULL, which is not allowed by the table definition.
|
| How can I make SQLObject create an INSERT statement without the field
| 'FIELD' so that the database will take over the calculation of the
| default value? It wouldn't make sense to duplicate the database logic of
| default value calculation in Python to be used in Col(default = ...)
This works for PostgreSQL (and should for all ANSI complient databases).
First, define this small helper:
class Default(object):
~ def __sqlrepr__(self, dbName):
~ return "DEFAULT"
DEFAULT = Default()
Then define your field as:
~ field = Col(default=DEFAULT)
- --
Stuart Bishop <stuart@...>
http://www.stuartbishop.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iD8DBQFBz8Q/AfqZj7rGN0oRAgc8AJ9R1gnlbnXqV85K2udMYAsqD/6x2QCeLcWK
L+KWBXSdprTtCSgH84xmRHE=
=Y5kr
-----END PGP SIGNATURE-----