Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

i try to build an function which returns a json.

I updated my mysql Workbench to 8.0.14 and tried the following code:

 SELECT JSON_OBJECT(
  'name_field', name_field,
  'address_field', address_field,
  'contact_age', contact_age
FROM contact;

But the following error appears:

Error Code: 1305. FUNCTION datalog.json_object does not exist

I thought that json_object is a standard mysql function, ins't it?

See here: JSON Object

Updating the Workbench app to 8 doesn't mean your MySQL server is at 8. What does SELECT VERSION(); output? – ceejayoz Jan 30, 2019 at 21:13

You're using MariaDB, not MySQL, and your version (MariaDB 10.1) is roughly comparable to MySQL 5.7, with some important differences. Your Workbench version is irrelevant - it's the server version that matters.

https://mariadb.com/kb/en/library/mariadb-vs-mysql-compatibility/

MariaDB 10.1 and above does not support MySQL 5.7's packed JSON objects. MariaDB follows the SQL standard and stores the JSON as a normal TEXT/BLOB. If you want to replicate JSON columns from MySQL to MariaDB, you should store JSON objects in MySQL in a TEXT column or use statement based replication. If you are using JSON columns and want to upgrade to MariaDB, you can either convert the JSON columns to TEXT or use mysqldump to copy these tables to MariaDB. In MySQL, JSON is compared according to json values. In MariaDB JSON strings are normal strings and compared as strings.

MariaDB 10.2.3 adds JSON_OBJECT support. https://mariadb.com/kb/en/library/json_object/

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.