How do I get date types to match between MSSQL and Postgres

65 views
Skip to first unread message

Brian

unread,
Sep 30, 2011, 1:43:50 AM9/30/11
to sqlal...@googlegroups.com
I have a postgres database local and stores data about our active students.  The remote database for our SIS (Student Information System) is using Microsoft SQL.

I'm using psycopg2 and pymssql libraries respectively.

The date object types I'm getting back from these databases are different, so when I do a session.merge() from the remote to the local databases, is_modified() gets set and the history for that date attribute shows that a change is pending, even when the date is exactly the same in both instances.

smalldatetime in MSSQL ends up as a datetime.datetime object, and date in postgresql ends up as a datetime.date.

Is there an easy way I can force the MSSQL attribute to return a datetime.date object, or do I just need to do a type lookup on the object to make a change before I merge each time?

Thanks in advance.

Michael Bayer

unread,
Sep 30, 2011, 8:54:28 AM9/30/11
to sqlal...@googlegroups.com
I'd build a TypeDecorator that receives the result back and ensures it's of the form you want:


"impl" here would be the type object you're currently using to represent the column type.



--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/5gBCNZKgyvUJ.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.

Reply all
Reply to author
Forward
0 new messages