所以我有一個模型Event
,我想創建一個名爲column_property
這start_time_local
應在時區的datetime
存儲在列timezone_name
當然在UTC日期時間存儲在start_time
。如何在sqlalchemy column_property中有一個原始的sql?
所以,如果 start_time is datetime(2014, 12, 3, 10, 00)
和 timezone_name is u'Europe/Helsinki'
然後, start_time_local
應datetime(2014, 12, 3, 12, 00)
當然在SQL的好,這是有可能通過執行這樣的事情:在SQLAlchemy的情況下
start_time::timestamptz AT TIME ZONE timezone_name
雖然我不知道如何通過column_property
或hybrid_property
的表達式來實現。我嘗試使用literal_column
作爲原始SQL執行此操作,但沒有成功,因爲它提供了一個錯誤消息,說明它們確實存在時找不到列start_time
和timezone_name
。所以我想這在這裏不是很有用。我也試圖找到任何功能,但所有那些與時間和時區相關的東西似乎只是在UTC和系統時間之間進行轉換,這對我來說並不是很有用。
這怎麼辦?