Using HeidiSQL 9.4.0.5125
I copied 2-4 exactly from the following sites and changed the table name to tmptreagency
and the column to name
.
http://www.geocities.jp/mickindex/database/db_tree_ns.html#LocalLink-level
Then,
SQL Error (1064): You have an error in your SQL syntax. Check the manual
that responses to your MySQL server version for the right syntax to
use near INTEGER)+1,``)AS name FROM tmptregency Mgrs,
tmptreagency MidMgrs, tmpt' at line 1
says the error.
I have tried again and again, but the error has not been fixed.
Could you tell me the cause of the error?
This is an actual SQL statement
SELECT LPAD(Mgrs.name, LENGTH(Mgrs.name) + CAST(COUNT(*)AS INTEGER) +1,')AS name
FROM tmptregency Mgrs, tmptregency MidMgrs, tmptregency Workers
WHERE Mgrs.lft BETWEEN MidMgrs.lft AND MidMgrs.rgt
AND MidMgrs.lft BETWEEN Workers.lft AND Workers.rgt
GROUP BY Mgrs.name, Mgrs.lft
ORDER BY MAX (Mgrs.lft);
It's like MySQL, so what about SIGNED instead of INTEGER?
When I tried only the CAST part, I got a syntax error with INTEGER.
Thank you for adding SQL.However, this time it didn't seem to be your copy-editing error, so I ran the same SQL with PostgreSQL 9.3, and it worked fine.(I don't know if it's exactly what the original author intended because I didn't input the data, but at least it doesn't get SQL errors.)
Tested with MySQL 5.6 on SQL Fiddle (HeidiSQL itself is a tool that can be used outside of MySQL, so if you are using MySQL as a DB, you should show it with tags, etc.If you look at the error message carefully, you will understand…) and First of all, the result of (By the way, this SQL didn't work with PostgreSQL 9.3, although the linked article states that CAST(...AS INTEGER)
are treated as syntax errors.
(After reading yud's post, I looked into it a little more and corrected it.In MySQL CAST
, the integer type specification is SIGNED [INTEGER]
, so you have to say AS SIGNED
or AS SIGNED INTEGER
regardless of the type before conversion.COUNT(*)
is an integer type, so CAST
would not be necessary, so when I created SQL like this, it started to work with MySQL 5.6.The version of MySQL is not specified in your question, so I can't say for sure what will happen in your environment (it shouldn't work because it's through HeidiSQL), but please try it.SELECT LPAD(Mgrs.name, LENGTH(Mgrs.name)+COUNT(*)+1,')AS name
FROM tmptregency Mgrs, tmptregency MidMgrs, tmptregency Workers
WHERE Mgrs.lft BETWEEN MidMgrs.lft AND MidMgrs.rgt
AND MidMgrs.lft BETWEEN Workers.lft AND Workers.rgt
GROUP BY Mgrs.name, Mgrs.lft
ORDER BY MAX (Mgrs.lft);
LPAD
is DBMS dependent, it seems difficult to write SQL that works with multiple DBMSs including subtle differences.)
919 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
578 Understanding How to Configure Google API Key
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.