postgres.functions module #424
theelderbeever
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
@theelderbeever There's a workaround for this at the moment, but it's completely undocumented ... When you create a The reason for this was if someone bypassed the ORM, the default value would still be correct in the database. For this schema: class Task(Table):
title = Varchar()
created_at = Timestamp() If you wanted to insert a bunch of rows which uses the databases from piccolo.columns.column_types import DEFAULT
await Task.insert(
Task(title="Do washing up", created_at=DEFAULT),
Task(title="Send package", created_at=DEFAULT)
) Or this instead if you prefer: from piccolo.columns.column_types import Unquoted
await Task.insert(
Task(title="Do washing up", created_at=Unquoted('current_timestamp')),
Task(title="Send package", created_at=Unquoted('current_timestamp'))
) It doesn't work as well for: task = Task(title="Do washing up", created_at=DEFAULT),
await task.save()
>>> task.created_at
DEFAULT # This should now be the datetime assigned by the database, rather than still being DEFAULT This can be fixed once this PR is finally merged in: #203 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I think it would be great to have a way to directly input database specific functions in queries and column defaults.
This might already exist but one that comes to mind is Postgres'
NOW()
function.Given the following it would be nice to use the database
NOW()
for the default when doing bulk inserts. It can be pretty valuable to have all records in the insert share an identical creation timestamp. Right now when generating records you have to explicitly pass a pre-instantiateddatetime.now()
value to the records rather than letting the database handle it. Not a big deal but a nice to have.Basically these could be function delegates
Beta Was this translation helpful? Give feedback.
All reactions