Paul Johnston wrote:

> In that case, I reckon using a database trigger will be best for this -
> it applies even when using raw SQL.

Yes.  This is what I said :-)

>>But then you can't say that you have a NOT NULL column because if you omit
>>the value then you'll get an SQL error...  (While you can say, for
>>example, "INSERT INTO table (column) VALUES (DEFAULT)" to get the default
>>value.)
>>  
>>
> I'm pretty sure the before insert trigger is called before it does the
> constraint checks. Have a go at knocking up a test case to confirm this.

You are correct.  You don't need to use triggers, though.  Using a default
function is enough (it might be implemented as a trigger depending on the
rdbms you use, but I can't say this is the only way to do that).

CREATE SEQUENCE some_sequence;
CREATE TABLE testing (
        columna integer not null default nextval('some_sequence'),
        columnb integer
);
INSERT INTO testing (columnb) VALUES (3);
INSERT INTO testing (columnb) VALUES (4);

Yelds:

SELECT * FROM testing;
 columna | columnb 
---------+---------
       1 |       3
       2 |       4
(2 rows)


On PostgreSQL here.  "nextval", in this case, doesn't appear listed as a
trigger but as a function used to modify the value of columna.

I believe that the point was that having functions as default (not
just "nextval" -- this is how PostgreSQL implements its SERIAL type) would
be interesting.  And I agree with that.  Specially if we could have
defaults based on other columns (triggers would probably be better here,
but it is possible to have that using other features of the database).



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to