如何将MySql数据库的JSON文本转换为postgres sql的JSON数据类型,我正在将JSON数据存储在Mysql的数据库表中,希望将其转换为postgres的JSON数据类型
Mysql创建表
CREATE TABLE IF NOT EXISTS `employee` (
`id` bigint(40) NOT NULL AUTO_INCREMENT,
`employee_id` bigint(40) NOT NULL,
`employee_info` text NOT NULL,
)
在employee_info中,我将{"employee_name":"abc“、"address":"1”、"emloyee_weight":"30“、”年龄“:”100“、”电话“:”9845236775“}存储在作为JSON的MySql数据库中。
并希望将其转换为postgressql的JSON数据类型。
发布于 2015-04-29 20:04:41
问题不应置之不理:-)
很简单:
Postgresql创建表
CREATE TABLE employee (
id bigserial primary key,
employee_id bigint NOT NULL,
employee_info json NOT NULL
);
,然后你可以使用一些魔法,比如:
select * from employee where employee_info->>'address' like '%Kr%';
或
select * from employee where CAST(employee_info->>'emloyee_weight' AS integer)>30;
注意postgres版本,应该是9.3或更高
http://sqlfiddle.com/#!15/edb87/1
https://stackoverflow.com/questions/29945276
复制相似问题