0

This query works on MariaDB, but not MySQL. I get a error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'integer) HOUR

This is a really dense query. So, even though I've looked through the manual I've had trouble identify which function is actually causing the issue.

SELECT  1 AS one
FROM sched_walks INNER JOIN walks ON walks.id = sched_walks.walk_id
WHERE sched_walks.d_acc = 1
  AND sched_walks.docent_id = 6
  AND (sched_walks.id != 714)
  AND (
    scheduled_for_utc <= '2018-03-17 14:34:31.000000'
      AND
    DATE_ADD(
      scheduled_for_utc,
      INTERVAL CONVERT(REPLACE(COALESCE(sched_duration, walks.duration), ' hours', ''), integer) HOUR
    ) >= '2018-03-17 12:34:31.000000'
  )
LIMIT 1

1 Answer 1

2

Use cast() instead:

  INTERVAL CAST(REPLACE(COALESCE(sched_duration, walks.duration), ' hours', '') as signed) HOUR

Actually, you can use convert() . . . the key is using signed or unsigned.

Or just use silent conversion:

  INTERVAL COALESCE(sched_duration, walks.duration) + 0 HOUR
Sign up to request clarification or add additional context in comments.

2 Comments

This fails on MariaDB. Is there anything that works for both?
Both of these should work in both databases. The integer is optional but signed and unsigned should work. (Note: I just fixed a typo in the second answer.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.