From: Stuart B. <st...@st...> - 2004-12-27 12:32:50
|
-----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 <st...@st...> http://www.stuartbishop.net/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQFBz8Q/AfqZj7rGN0oRAgc8AJ9R1gnlbnXqV85K2udMYAsqD/6x2QCeLcWK L+KWBXSdprTtCSgH84xmRHE= =Y5kr -----END PGP SIGNATURE----- |