Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> There has to be an option to pass a static default value

Does there, though? You can always set `Column(default = lambda: 1234)`



Yes, because you're creating a table and the value needs to be encoded as string in the CRATE TABLE query. You could in theory pass a lambda which is disassembled in SQLalchemy, then checked against the pattern returning a constant, then the constant itself gets used... But I'm not sure SQLalchemy would go that way. It's not as crazy as Linq.

To be explicit: You're not seeing a function called later in python. You're setting an attribute on a database table.


No[0], default= is inserted into the DML queries by the client. A DDL DEFAULT clause is only generated if you set server_default= instead.

[0]: https://docs.sqlalchemy.org/en/20/core/defaults.html




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: