Python MySQLdb.constants.FIELD_TYPE.TIMESTAMP Examples

The following are 2 code examples of MySQLdb.constants.FIELD_TYPE.TIMESTAMP(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module MySQLdb.constants.FIELD_TYPE , or try the search function .
Example #1
Source File: mysql_to_gcs.py    From airflow with Apache License 2.0 5 votes vote down vote up
def query(self):
        """
        Queries mysql and returns a cursor to the results.
        """
        mysql = MySqlHook(mysql_conn_id=self.mysql_conn_id)
        conn = mysql.get_conn()
        cursor = conn.cursor()
        if self.ensure_utc:
            # Ensure TIMESTAMP results are in UTC
            tz_query = "SET time_zone = '+00:00'"
            self.log.info('Executing: %s', tz_query)
            cursor.execute(tz_query)
        self.log.info('Executing: %s', self.sql)
        cursor.execute(self.sql)
        return cursor 
Example #2
Source File: mysql_to_gcs.py    From airflow with Apache License 2.0 5 votes vote down vote up
def field_to_bigquery(self, field):
        field_type = self.type_map.get(field[1], "STRING")
        # Always allow TIMESTAMP to be nullable. MySQLdb returns None types
        # for required fields because some MySQL timestamps can't be
        # represented by Python's datetime (e.g. 0000-00-00 00:00:00).
        field_mode = "NULLABLE" if field[6] or field_type == "TIMESTAMP" else "REQUIRED"
        return {
            'name': field[0],
            'type': field_type,
            'mode': field_mode,
        }