| 211 | |
| 212 | |
| 213 | class Now(Func): |
| 214 | template = "CURRENT_TIMESTAMP" |
| 215 | output_field = DateTimeField() |
| 216 | |
| 217 | def as_postgresql(self, compiler, connection, **extra_context): |
| 218 | # PostgreSQL's CURRENT_TIMESTAMP means "the time at the start of the |
| 219 | # transaction". Use STATEMENT_TIMESTAMP to be cross-compatible with |
| 220 | # other databases. |
| 221 | return self.as_sql( |
| 222 | compiler, connection, template="STATEMENT_TIMESTAMP()", **extra_context |
| 223 | ) |
| 224 | |
| 225 | def as_mysql(self, compiler, connection, **extra_context): |
| 226 | return self.as_sql( |
| 227 | compiler, connection, template="CURRENT_TIMESTAMP(6)", **extra_context |
| 228 | ) |
| 229 | |
| 230 | def as_sqlite(self, compiler, connection, **extra_context): |
| 231 | return self.as_sql( |
| 232 | compiler, |
| 233 | connection, |
| 234 | template="STRFTIME('%%%%Y-%%%%m-%%%%d %%%%H:%%%%M:%%%%f', 'NOW')", |
| 235 | **extra_context, |
| 236 | ) |
| 237 | |
| 238 | def as_oracle(self, compiler, connection, **extra_context): |
| 239 | return self.as_sql( |
| 240 | compiler, connection, template="LOCALTIMESTAMP", **extra_context |
| 241 | ) |
| 242 | |
| 243 | |
| 244 | class TruncBase(TimezoneMixin, Transform): |