Mysql, search in JSon field? - mysql

In my MySQL Database, some fields are "JSon text" fields.
Seoemtimes, I need to search/select from what these Json contain.
How should I do ?
Is there MySQL tools for achieving it ?
Thanks

http://labs.mysql.com/ refeers to MySQL JSon.
It is not fit for production yet.
Using a specific JSON type, rather than VARCHAR or TEXT, is definetely in progress by the MySQL Labs'.
It can be used with the latest MySQL releases, but seems quite beta.
Anyway, it's promising.
Googling a bit provides even documentation about it.
JSON type is to be a new type for MySQL.
it will make possible to search in Json-typed filed, and also to insert/delete/select, etc.

Related

Search across two different databases (mysql and postgres)

Is it possible to search for something that is in two databases? For example, I want to do a "starts with" search on a column in Postgres as well as a column in MySQL where one is "name" and one is "email"
Copying over data is not reliable as new data will be created in both databases constantly.
Yes, it is possible. For the "starts with" part, you should be able to use the standard Postgres string functions, of which starts_with is one, and indexing on the desired columns.
Getting the data from MySQL is the more complicated part.
You would most likely want to use a foreign data wrapper (e.g. FDW) from Postgres to access the MySQL data, and then handle the unioning of it (or other desired processing) with the Postgres data for returning the combined data set.
You could write your own FDW if you have particularly specific requirements, or you could try an open source one, such as this one from EnterpriseDB. EnterpriseDB is a Postgres consultancy and offers their own Postgres version, but the doc on the Github page for this says it is compatible with base Postgres as well as their own version.

What is the best way to store a pretty large JSON object in MySQL

I'm building a Laravel app the core features are driven with rather large JSON objects. (the largest ones are between 1000-1500 lines).
I know there are better data base choices than MySQL for storing files and blocks of data, but for various reasons I will need to use MySQL for the application.
So my question is, how to I store my JSON objects most effective in MySQL? I will not need to do any queries on the column that holds the data, there will be other columns for identifying it. Something like this:
id, title, created-at, updated-at, JSON-blobthingy
Any ideas?
You could use the JSON data type if you have MySQL version 5.7.8 or above.
You could store the JSON file on the server, and simply reference its location via MySQL.
You could use also one of the TEXT types.
The best answer i can give is to use MySQL 5.7. On this version the new column type JSON are supported. Which handles large JSON very well (obviously).
https://dev.mysql.com/doc/refman/5.7/en/json.html
You could compress the data before inserting it if you don't need it searchable. I'm using the 'zlib' library for that
Simply, you can use the type longblob which can handle up to 4GB of data for the column holding the large JSON object where you can insert, update, and read this column normally as if it is text or anything else!

How to query data which is json datatype from postgresql in sqlalchemy?

In sqlalchemy, I use classical mapping and autoload=True. I want to query data which is jsontype from postgresql.
D:\Python27\lib\site-packages\sqlalchemy\dialects\postgresql\base.py:1706: SAWarning: Did not recognize type 'json' of column 'comm_media_alias'name, format_type, default, notnull, domains, enums, schema)
how to deal with this problem
The JSON type in PostgreSQL is a relatively new data type in PostgreSQL, and thus SQLAlchemy has only recently added functionality to properly detect it. At the time of this question, SQLAlchemy would not be able to detect the "JSON" column type, as doing so relied on functionality that it did not yet support.
SQLAlchemy 0.9 was released on December 30th, 2013. This version contains support for the PostgreSQL JSON data type, so I would recommend upgrading to this version and trying again.
If you can't upgrade (or the upgrade still isn't working for you), you can also change your column type to something else (like TEXT).
Another thing to note about this is that it is not an error: it is a warning. I'm not sure what SQLAlchemy will actually try to do when it is working with the column that is a JSON type, but it might end up working anyway.

Best way to implement a keyword search from a MySQL CLOB or VARCHAR column

I have to implement a keyword search from a CLOB column in my MySQL / JPA project.
I know that I can use a JPA query something like SELECT something FROM something WHERE..., but are there any other 'Enterprise' way of doing this?
(I am asking this question keeping Hibernate search in mind, but there seems to be no equivalent for Hibernate search in JPA)
What do you mean under "enterprise"-way? Hibernate is pretty enterprisish as most of Fortune-500 companies actually use that in one or another way. Though latest Hibernate Search version is still in beta, that's probably not what most of the enterprises will accept. But there is a stable release you can probably use.
And you can still use Apache Lucene to index your CLOBs and search in the index instead of DB. That's what basically Hibernate Search is also doing under the hood. And that's the aproach used by many companies.
UPDATE: I never used Hibernate Search as a separate product and what they say in their documentation is that Hibernate Core is a requirement. But you can still try plain Lucene instead.

Storing JSON as key value pair

My question is how to store a nested JSON as key value in mysql table. Earlier I thought of storing it as CSV but on deep diving I found it like it would be difficult to query those values and to manage as well.
Please help me in giving alternate solutions of how and where to store JSON.
The version of MySQL I am using does not support the JSON data type
If you are using MySQL 5.7, you can store ans query JSON objects. Look at this link for more details and examples.
Since MySQL 5.7 a native JSON data type is supported.
See also https://dev.mysql.com/doc/refman/5.7/en/json.html
If your MySQL version is lower the only option left is to store it as text. Otherwise you will not be able to store it in a simple key value pair manner.