Home > Database > Mysql Tutorial > PostgreSQL 9.2中的json存储表示和检索

PostgreSQL 9.2中的json存储表示和检索

WBOY
Release: 2016-06-07 14:53:37
Original
1138 people have browsed it

PostgreSQL 9.2中的json存储表示和检索 其解决方案就是使用hstore类型,使用它,先得创建对应的扩展。 www.2cto.com 下面只列出简单的使用示例: iihero=# create extension hstore; CREATE EXTENSION iihero=# iihero=# select a=1,b=2::hstore; hstore ---


PostgreSQL 9.2中的json存储表示和检索

 

其解决方案就是使用hstore类型,使用它,先得创建对应的扩展。

  www.2cto.com  

下面只列出简单的使用示例:

 

iihero=# create extension hstore;

CREATE EXTENSION

iihero=#

iihero=# select 'a=>1,b=>2'::hstore;

  hstore

--------------------

 "a"=>"1", "b"=>"2"

(1 row)

 

iihero=# insert into tjson values(1, 'a=>1, b=>2, c=>3'::hstore);

INSERT 0 1

iihero=# insert into tjson values(2, 'a=>2, b=>3, c=>4'::hstore);

INSERT 0 1

iihero=# select * from tjson where col2 @>'a=>1';

 id | col2

----+------------------------------

  1 | "a"=>"1", "b"=>"2", "c"=>"3"

(1 row)

 

iihero=# select * from tjson where col2 @>'a=>1' and col2 @>'b=>2';

 id | col2

----+------------------------------

  1 | "a"=>"1", "b"=>"2", "c"=>"3"

(1 row)

 

所不同的,只是语法表现形式的不同。还可以充分利用索引。

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template