Error in SQL Syntax - MySQL Event issue

This section covers the Meteobridge PRO units exclusively

Moderator: Mattk

Post Reply
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: Fri Feb 01, 2019 10:06 pm

Error in SQL Syntax - MySQL Event issue

Post by mpriest »

I am using this query in the MySQL services tab from a Meteobridge Pro:

INSERT INTO 'wassenaarstrand' ('ID', 'DateTime', 'TempOutCur', 'WindSpeedCur', 'WindDirCur', 'WindGust10', 'WindDirAvg10') VALUES (NULL, '[YYYY]-[MM]-[DD] [hh]:[mm]:[ss]', '[th0temp-act]', '[wind0wind-act=kn]', '[wind0dir-act]', '[wind0wind-max10=kn]', '[wind0dir-avg10]')

The response is an error in SQL syntax.

Could you help me please with spotting the error ?

User avatar
Expert Boarder
Expert Boarder
Posts: 103
Joined: Wed Jul 05, 2017 5:22 pm
Location: CO, USA

Re: Error in SQL Syntax - MySQL Event issue

Post by Ag2000CO »

I see several problems.
1. The table name in the INSERT query should not be quoted. INSERT INTO wassenaarstrand ...

2. If you are not sure of the column order in the table include the column names in a comma separated list in the order you will provide the VALUES without quotes.
INSERT INTO wassenaarstrand (ID, DateTime, TempOutCur, WindSpeedCur, WindDirCur, WindGust10, WindDirAvg10) VALUES ...

3. If you know the column order in the table wassenaarstrand then you do not need to include the column names, BUT you must present the VALUES in the same order as the table columns were defined. NOTE the values are quoted (except the defined value NULL).
INSERT INTO wassenaarstrand VALUES (NULL, '[YYYY]-[MM]-[DD] [hh]:[mm]:[ss]', '[th0temp-act]', '[wind0wind-act=kn]', '[wind0dir-act]', '[wind0wind-max10=kn]', '[wind0dir-avg10]')

Of course MB when processing the request will replace the values within square brackets [] with the appropriate values before submitting the MySQL query.

A. I assumed that the first table column, ID, was defined as "AUTO_INCREMENT" Otherwise the VALUES (NULL... would also be an error in an INSERT query.
Say what you will about Sisyphus. He always has work.

Post Reply