6 ms·
I'm not familiar with this library, how does `text("(now())")` evaluate and why there are extra parentheses? And should that be a lambda expression as well, so
by nikonyrh 2y ago
I'm not familiar with this library, how does `text("(now())")` evaluate and why there are extra parentheses? And should that be a lambda expression as well, so that `create_date` isn't just the timestamp when the python process was started?
- yeputons 2y agoI suspect it's either just an SQL expression sent to the DB, or it's `eval`ed in Python.
- openmajestic 2y agoIIRC, the difference is server_default vs default. One is generated DB-side, the other in the Python code. Might be wrong on that, but that's my recollection
- oxidant 2y agoMy guess is that "now()" is the DB function that returns the current timestamp.
- jhardy54 2y agoI’ll note that the bug is in the `id` column, but the `created_date` is likely passing the string “now()” to invoke SQL’s NOW(), deferring the timestamp creation to the database.
- crote 2y agoI'm not familiar with the library either, but that seems to be a SQL expression executed on the database server. It's basically a copy-paste from the official documentation[0]. So no, not a lambda expression, because it's not computed in Python. As to the extra parentheses: I bet that's a force-of-habit thing to prevent potential issues. For example, it seems Sqlite requires them for exactly this kind of default definition[1]. It could also read to nasty bugs when the lack of parentheses in the resulting SQL could result in a different parse than expected[2]. Adding them just-to-be-safe isn't the worst thing to do. [0]: https://docs.sqlalchemy.org/en/13/core/metadata.html https://docs.sqlalchemy.org/en/13/core/metadata.html [1]: https://github.com/sqlalchemy/sqlalchemy/issues/4474 https://github.com/sqlalchemy/sqlalchemy/issues/4474 [2]: https://github.com/sqlalchemy/sqlalchemy/issues/5344 https://github.com/sqlalchemy/sqlalchemy/issues/5344
- nikonyrh 2y agoAah that makes sense, thanks!