Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed RD-15252: Missing handling of TIMESTAMPTZOID #11

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ srcdir = .
MODULE_big = multicorn
OBJS = src/errors.o src/python.o src/query.o src/multicorn.o
# Uncomment to have symbols in debuggers
# PG_CFLAGS = -g -O0
PG_CFLAGS = -g -O0


DATA = $(filter-out $(wildcard sql/*--*.sql),$(wildcard sql/*.sql))
Expand Down
29 changes: 28 additions & 1 deletion src/python.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static PyObject *datumFloat4ToPython(Datum datum, ConversionInfo * cinfo);
static PyObject *datumFloat8ToPython(Datum datum, ConversionInfo * cinfo);
static PyObject *datumDateToPython(Datum datum, ConversionInfo * cinfo);
static PyObject *datumTimestampToPython(Datum datum, ConversionInfo * cinfo);
static PyObject *datumTimestampTzToPython(Datum datum, ConversionInfo * cinfo);
static PyObject *datumIntToPython(Datum datum, ConversionInfo * cinfo);
static PyObject *datumArrayToPython(Datum datum, Oid type, ConversionInfo * cinfo);
static PyObject *datumByteaToPython(Datum datum, ConversionInfo * cinfo);
Expand Down Expand Up @@ -1703,7 +1704,31 @@ datumTimestampToPython(Datum datum, ConversionInfo * cinfo)
pg_tm_value->tm_mday,
pg_tm_value->tm_hour,
pg_tm_value->tm_min,
pg_tm_value->tm_sec, 0);
pg_tm_value->tm_sec,
fsec);
pfree(pg_tm_value);
return result;
}

PyObject *
datumTimestampTzToPython(Datum datum, ConversionInfo * cinfo)
{
struct pg_tm *pg_tm_value = palloc(sizeof(struct pg_tm));
PyObject *result;
fsec_t fsec;
int tzp;
const char* tzn;

PyDateTime_IMPORT;
timestamp2tm(DatumGetTimestampTz(datum), &tzp, pg_tm_value, &fsec,
&tzn, session_timezone);
result = PyDateTime_FromDateAndTime(pg_tm_value->tm_year,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to pass the timezone offset.

pg_tm_value->tm_mon,
pg_tm_value->tm_mday,
pg_tm_value->tm_hour,
pg_tm_value->tm_min,
pg_tm_value->tm_sec,
fsec);
pfree(pg_tm_value);
return result;
}
Expand Down Expand Up @@ -1805,6 +1830,8 @@ datumToPython(Datum datum, Oid type, ConversionInfo * cinfo)
return datumDecimalToPython(datum, cinfo);
case DATEOID:
return datumDateToPython(datum, cinfo);
case TIMESTAMPTZOID:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe Postgres stores a timestamp with time zone after having shifted it by its timezone offset. Does that mean we're getting a timestamp without timezone, but shifted?

return datumTimestampTzToPython(datum, cinfo);
case TIMESTAMPOID:
return datumTimestampToPython(datum, cinfo);
case FLOAT4OID:
Expand Down