Uploaded image for project: 'Teiid'
  1. Teiid
  2. TEIID-1466

MySQL syntax error in cast from date to timestamp

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 7.4
    • 7.3
    • Query Engine
    • None

    Description

      If you have a table in MySQL with a field declared of type DATE, queries which need to cast that field to a timestamp fail.

      E.g. consider a MySQL table T with a field A of type DATE, and create the corresponding source model. If you submit the following two queries, the first works and the second fails.

      SELECT A FROM T;
      
      SELECT CAST(A AS TIMESTAMP) FROM T;
      

      This happens because in the second case, Teiid pushes to MySQL a query like the following:

      SELECT CAST(g_0.A AS TIMESTAMP) FROM T AS g_0;
      

      That syntax is not valid because MySQL doesn't support casting to timestamp. I think that if it would be possible to cast to datetime instead of timestamp, the query will work. Unfortunately, Teiid doesn't support the datetime data type... so there's no solution.

      I've found two workarounds, which prevent Teiid from pushing the cast to the source:

      1. The first is to change the data type at the source, that is, by declaring the A field as DATETIME instead of DATE. But this is not alway possible.
      2. The other is to declare the field of type dateTime or timestamp in the source model, while leaving the "Native Type" property to DATE

      Attachments

        Activity

          People

            rhn-engineering-shawkins Steven Hawkins
            ventuc Claudio Venturini (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: