Error in SQL Syntax - MySQL Event issue

This section covers the Meteobridge PRO units exclusively

Moderator: Mattk

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

Error in SQL Syntax - MySQL Event issue

Post by mpriest » Fri Feb 01, 2019 10:20 pm

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
Ag2000CO
Senior Boarder
Senior Boarder
Posts: 56
Joined: Wed Jul 05, 2017 5:22 pm
Location: CO, USA
Contact:

Re: Error in SQL Syntax - MySQL Event issue

Post by Ag2000CO » Sat Feb 02, 2019 5:49 am

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.
Lou
Say what you will about Sisyphus. He always has work.

Post Reply