villebro commented on a change in pull request #8464: [SIP-15] Fixing datetime 
conversion and SQL literal
URL: 
https://github.com/apache/incubator-superset/pull/8464#discussion_r340267780
 
 

 ##########
 File path: superset/db_engine_specs/oracle.py
 ##########
 @@ -39,7 +40,10 @@ class OracleEngineSpec(PostgresBaseEngineSpec):
     }
 
     @classmethod
-    def convert_dttm(cls, target_type: str, dttm: datetime) -> str:
-        return ("""TO_TIMESTAMP('{}', 
'YYYY-MM-DD"T"HH24:MI:SS.ff6')""").format(
-            dttm.isoformat()
-        )
+    def convert_dttm(cls, target_type: str, dttm: datetime) -> Optional[str]:
+        tt = target_type.upper()
+        if tt == "DATE":
+            return f"TO_DATE('{dttm.date().isoformat()}', 'YYYY-MM-DD')"
+        if tt == "TIMESTAMP":
+            return f"""TO_TIMESTAMP('{dttm.isoformat(sep=" ", 
timespec="microseconds")}', 'YYYY-MM-DD HH24:MI:SS.ff6')"""  # pylint: 
disable=line-too-long
 
 Review comment:
   I think cleaner handling here would be to force the T into the Oracle 
formatter:
   
   ```python
   f"""TO_TIMESTAMP('{dttm.isoformat(timespec="microseconds")}', 
'YYYY-MM-DD"T"HH24:MI:SS.ff6')""" (I assume microseconds is default?)
   ```
   
   See: 
https://stackoverflow.com/questions/26671557/convert-string-iso-8601-date-to-oracles-timestamp-datatype
   
   I tested it and it works correctly.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to