diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-05-05 00:53:15 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-05-15 14:27:23 +0100 |
commit | 5e3f240ac96ddb27dee4cb03f1c857be1ced8ff9 (patch) | |
tree | cb176023b16bfe1af1dfc3d64ad7be42414f51ad /psycopg/adapter_datetime.c | |
parent | 60e7522e476b8b727e1dfa8535b715d0f66fa0ea (diff) | |
download | psycopg2-5e3f240ac96ddb27dee4cb03f1c857be1ced8ff9.tar.gz |
Cast datetime into timestamptz when the tzinfo field is set.
Diffstat (limited to 'psycopg/adapter_datetime.c')
-rw-r--r-- | psycopg/adapter_datetime.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/psycopg/adapter_datetime.c b/psycopg/adapter_datetime.c index deaf59f..24d158c 100644 --- a/psycopg/adapter_datetime.c +++ b/psycopg/adapter_datetime.c @@ -57,6 +57,7 @@ static PyObject * pydatetime_str(pydatetimeObject *self) { if (self->type <= PSYCO_DATETIME_TIMESTAMP) { + PyObject *tz; /* Select the right PG type to cast into. */ char *fmt = NULL; @@ -68,7 +69,10 @@ pydatetime_str(pydatetimeObject *self) fmt = "'%s'::date"; break; case PSYCO_DATETIME_TIMESTAMP: - fmt = "'%s'::timestamp"; + tz = PyObject_GetAttrString(self->wrapped, "tzinfo"); + if (!tz) { return NULL; } + fmt = (tz == Py_None) ? "'%s'::timestamp" : "'%s'::timestamptz"; + Py_DECREF(tz); break; } |