Why select json data not working in the mariadb? - mysql

My query like this :
select `information`->'$."full_name"' as `homeroom`
from `classes`
If the query run in my database local, it works. No error
But if the query run in my database server, it does not works. There exist error like this :
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '>'$."full_name"' as `homeroom`
from `classes` LIMIT 0, 25' at line 1
If I run select version(),
My version database local : 8.0.15
My version database server : 10.0.38-MariaDB
Seems it does not work because my database server using mariadb
How can I solve this problem?
Update :
I using data type text to infomation field

JSON functions weren't added to MariaDB until version 10.2.3. If you can't upgrade you will have to process the data in your application. Note that even in versions that support JSON, they don't support the -> notation (reference) so you will have to rewrite the query as
JSON_EXTRACT(information, '$.full_name')

Related

Sql Syntax error with Doctrine, probably because of change of Mysql version

I've programmed a project in symfony and mysql 5.6. then I uploaded my project to a remote server on 1&1. the remote server has mysql 5.7 version. All doctrine queries run ok and without problem. But when a user searches something, a request will be sent to the server and a doctrine query will be executed. Here it returns the following error:
SQLSTATE[42000]: Syntax error or access violation: 1064 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)
BETWEEN 1940 AND 2002) AND u0_.id <> 2' at line 1
I think, it is probably because of different versions of mysql. Because on localhost it runs without problem
Can you please help me how to solve it? is there a way to regenerate all the migrations according the new mysql version? or may be there is another solution?
thanks
I was using CAST('number' as integer) in mysql 5.6. It did ok. However in mysql 5.7 and I do not know why, it does not run ok. So I changed it to CAST('number' as UNSIGNED) and it works ok

'Syntax Error' when using Database Navigator for PyCharm

I have a project with a MySQL database to which I connected using the Database Navigator plugin.
Now when I open the DB Browser window, select the database and click on "Open DB console" and insert the query
SELECT CAST('2017-08-29' AS DATE);
for one, the IDE highlights CAST as an unknown identifier:
and, additionally, when I try to execute the statement, I get the error
Error executing SELECT statement. 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 '' at line 1 - Connection: test: 112ms
However, to my knowledge, this is valid MySQL, at least this page suggests so.
I am also able to perform MySQL queries with casts from a python script that builds the connection itself.
What am I doing wrong here? Do I have to configure the dialect for Database Navigator?

MySQL syntax error - dropping foreign key if exist

The following ALTER statement is working fine on my local (xamp), but on my server (Debian), I'm getting this 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
'IF EXISTS `foreign_key1`' at line 1
This is the query:
ALTER TABLE `table` DROP FOREIGN KEY IF EXISTS `foreign_key1`;
How do I fix the error?
Sounds like your development environment is running MariaDB, and your server is running MySQL.
MySQL doesn't support the IF EXISTS in an ALTER TABLE statement.
That syntax is supported in MariaDB 10.0.
To confirm the version running in each environment, we could execute
SHOW VARIABLES LIKE 'version'
MariaDB https://mariadb.com/kb/en/mariadb/alter-table/
MySQL https://dev.mysql.com/doc/refman/5.7/en/alter-table.html
I don't know if this answers the question that was asked... "What is the explanation for the observed behavior?" (Was that the question?)

Parameterize MySQL workbench statements: How to define variables

I'm trying to parameterize a set of frequently used queries in my workbench.
This works:
select * from providers where id='112233';
This
WbVarDef var1=112233;
select * from providers where id='$[var1]';
gives error
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'from providers where id='112233'' at line 1
My reference was this.
Just to be clear, these are in the MySQL workbench and not a workbench script file or a mysql script file.
In MySQL, syntax for setting variable is below.
SET #var1 = '112233';
and using the variable would be as below.
select * from providers where id=#var1;
Check out MySQL documentation for more information Link to MySQL Documentation
Based on your tag mysql-workbench, I find it simply to be a case where the referenced documentation and use is not relevant to what you are using.
Back up the hierarchy from your link to this http://www.sql-workbench.net/
and you will read:
Please note that SQL Workbench/J has no relation to the product MySQL
Workbench which is maintained and owned by Oracle. If you
are looking for MySQL Workbench support please contact Oracle.

SQL syntax error in MySQL unsing a cast(Partition as Signed)

I have to support an application on a MySQL server. I can´t change the source code so I can´t change the used syntax.
My problem is that I always get an syntax error like this:
Microsoft OLE DB Provider for ODBC Drivers [-2147217900]
[MySQL][ODBC 5.1 Driver][mysqld-5.6.26]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 'Partition as Signed)' at
line 1
I looked into the log file and found the problem in this line:
Select *
from XYZ
where `Type`='something'
and Client='{3DBEA33A-9F0A-4e86-8354-F652713EA458}'
order by Cast(Partition as Signed);
I always get this error when the "Cast(Partition as Signed)" appears.
Is there any way to configure the server to accept this syntax?
I´m using MySQL (x64) 5.6.26 with InnoDB.
Partition is reserved word.
http://dev.mysql.com/doc/refman/5.6/en/keywords.html
you should use it with backticks
`Partition`