PostgreSQL的hstore初步学习
安装hstore:
进入源代码的 /contrib/hstore 目录,然后执行gmake 和 gmake install:
[root@pg200 hstore]# gmake
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fpic -I. -I. -I../../src/include -D_GNU_SOURCE -c -o hstore_io.o hstore_io.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fpic -I. -I. -I../../src/include -D_GNU_SOURCE -c -o hstore_op.o hstore_op.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fpic -I. -I. -I../../src/include -D_GNU_SOURCE -c -o hstore_gist.o hstore_gist.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fpic -I. -I. -I../../src/include -D_GNU_SOURCE -c -o hstore_gin.o hstore_gin.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fpic -I. -I. -I../../src/include -D_GNU_SOURCE -c -o hstore_compat.o hstore_compat.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fpic -I. -I. -I../../src/include -D_GNU_SOURCE -c -o crc32.o crc32.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fpic -shared -o hstore.so hstore_io.o hstore_op.o hstore_gist.o hstore_gin.o hstore_compat.o crc32.o -L../../src/port -Wl,-rpath,'/usr/local/pgsql/lib',--enable-new-dtags
gmake:
[root@pg200 hstore]# gmake install
/bin/mkdir -p '/usr/local/pgsql/lib'
/bin/mkdir -p '/usr/local/pgsql/share/extension'
/bin/mkdir -p '/usr/local/pgsql/share/extension'
/bin/sh ../../config/install-sh -c -m hstore.so '/usr/local/pgsql/lib/hstore.so'
/bin/sh ../../config/install-sh -c -m ./hstore.control '/usr/local/pgsql/share/extension/'
/bin/sh ../../config/install-sh -c -m ./hstore--1.1.sql ./hstore--1.0--1.1.sql ./hstore--unpackaged--1.0.sql '/usr/local/pgsql/share/extension/'
[root@pg200 hstore]#
然后,启动PostgreSQL,再启动psql后,安装hstore扩展:
postgres=# create extension hstore;
CREATE EXTENSION
postgres=#
进行测试:
建表:
postgres=# create table hstore_test(item_id serial, data hstore);
NOTICE: CREATE TABLE will create implicit sequence "hstore_test_item_id_seq" for serial column "hstore_test.item_id"
CREATE TABLE
postgres=#
插入数据:
postgres=# INSERT INTO hstore_test (data) VALUES ('"key1"=>"value1", "key2"=>"value2", "key3"=>"value3"');
INSERT 0 1
postgres=# select * from hstore_test;
item_id | data
---------+------------------------------------------------------
1 | "key1"=>"value1", "key2"=>"value2", "key3"=>"value3"
(1 row)
postgres=#
修改数据:
postgres=# UPDATE hstore_test SET data = delete(data, 'key2')
postgres-# ;
UPDATE 1
postgres=# select * from hstore_test;
item_id | data
---------+------------------------------------
1 | "key1"=>"value1", "key3"=>"value3"
(1 row) postgres=#
postgres=# UPDATE hstore_test SET data = data || '"key4"=>"some value"'::hstore;
UPDATE 1
postgres=# select * from hstore_test;
item_id | data
---------+----------------------------------------------------------
1 | "key1"=>"value1", "key3"=>"value3", "key4"=>"some value"
(1 row) postgres=#
按Key值查询:
postgres=# SELECT * FROM hstore_test WHERE data ? 'key4';
item_id | data
---------+----------------------------------------------------------
1 | "key1"=>"value1", "key3"=>"value3", "key4"=>"some value"
(1 row) postgres=#
postgres=# SELECT * FROM hstore_test WHERE NOT data ? 'key5';
item_id | data
---------+----------------------------------------------------------
1 | "key1"=>"value1", "key3"=>"value3", "key4"=>"some value"
(1 row) postgres=# SELECT * FROM hstore_test WHERE data @> '"key4"=>"some value"'::hstore;
item_id | data
---------+----------------------------------------------------------
1 | "key1"=>"value1", "key3"=>"value3", "key4"=>"some value"
(1 row) postgres=# SELECT data -> 'key4' FROM hstore_test;
?column?
------------
some value
(1 row) postgres=# SELECT item_id, (each(data)).* FROM hstore_test WHERE item_id = 2;
item_id | key | value
---------+-----+-------
(0 rows) postgres=# SELECT item_id, (each(data)).* FROM hstore_test WHERE item_id = 1;
item_id | key | value
---------+------+------------
1 | key1 | value1
1 | key3 | value3
1 | key4 | some value
(3 rows) postgres=#
PostgreSQL的hstore初步学习的更多相关文章
- 初步学习pg_control文件之十四
接前文 初步学习pg_control文件之十三 看如下几个: /* * Parameter settings that determine if the WAL can be used for arc ...
- 初步学习pg_control文件之九
接前文,初步学习pg_control文件之八 来看这个: pg_time_t time; /* time stamp of last pg_control update */ 当初初始化的时候,是这样 ...
- json2.js的初步学习与了解
json2.js的初步学习与了解,想要学习json的朋友可以参考下. json2.js的初步学习与了解 1.)该js的下载地址是:http://www.json.org/json2.js 2.)在页面 ...
- 老周的ABP框架系列教程 -》 一、框架理论初步学习
老周的ABP框架系列教程 -- 一.框架理论初步学习 1. ABP框架的来源与作用简介 1.1 简介 1.1.1 ABP框架全称为"ASP.NET Boilerplate ...
- 初步学习nodejs,业余用node写个一个自动创建目录和文件的小脚本,希望对需要的人有所帮助
初步学习nodejs,业余用node写个一个自动创建目录和文件的小脚本,希望对需要的人有所帮助,如果有bug或者更好的优化方案,也请批评与指正,谢谢,代码如下: var fs = require('f ...
- EF Codefirst 初步学习(二)—— 程序管理命令 更新数据库
前提:搭建成功codefirst相关代码,参见EF Codefirst 初步学习(一)--设置codefirst开发模式 具体需要注意点如下: 1.确保实体类库程序生成成功 2.确保实体表类库不缺少 ...
- 初步学习python
自计算机诞生以来,也伴随着计算机语言的诞生,现在,全世界的编程语言有600多种,但流行的编程语言也就20多种. Java和C一直占据着前两名.但是近年来伴随着人工智能的发展,Python发展迅猛,以其 ...
- Git的初步学习
前言 感谢! 承蒙关照~ Git的初步学习 为什么要用Git和Github呢?它们的出现是为了用于提交项目和存储项目的,是一种很方便的项目管理软件和网址地址. 接下来看看,一家公司的基本流程图: 集中 ...
- 语法分析器初步学习——LISP语法分析
语法分析器初步学习——LISP语法分析 本文参考自vczh的<如何手写语法分析器>. LISP的表达式是按照前缀的形式写的,比如(1+2)*(3+4)在LISP中会写成(*(+ 1 2)( ...
随机推荐
- MySQL面试宝典
==============================================# 参数==============================================auto ...
- ES 6 装饰器与 React 高阶组件
关于 Decorator 到底是 ES 6 引入的还是 ES 7 引入的我也不是很明白了,两种说法都有,这种问题懒得纠结了--在用的时候发现这个东西很好用,平常用处可能不大,但是结合 React 就很 ...
- 让IE6、7、8兼容@media属性
通常做页面适配的时候,经常会用到@media属性,对不同屏幕范围内的元素设置不同的样式.但是@media属性不兼容IE8及IE8以下的浏览器 解决方法: 直接在页面中引入respond.src.js即 ...
- iOS js 使用与JSContext
JSContext:js执行环境,包含了js执行时所需要的所有函数和对象: js执行时,会在执行环境搜索需要的函数然后执行,或者保存传入的变量或函数: JSContext *jsContext = [ ...
- 远程调用内核接口的封装类(RCKObjs)
RCK 包括 Application, Function, Connection, Command, Response 和 Fields 六 大类, 其主要功能例如以下: a. Applica ...
- ERROR: Repository not found. ////Git, but is not registered in the Settings.
1.ERROR: Repository not found. 这个问题是因为在你推送的github账户中,并没有这个Repository. 解决方法: 1)检查自己的github中的Repositor ...
- LayIM.AspNetCore Middleware 开发日记(二)预备知识介绍
前言 开发一个AspNetCore的中间件需要理解RequestDelegate.另外,还需要理解.NET Core中的依赖注入.还有一个就是内嵌资源的访问.例如:EmbeddedFileProvid ...
- [转]未能加载文件或程序集 CrystalDecisions.Web Version=10.2.3600解决方法
找到你开发的机器上VS安装目录中的SDK\v2.0\BootStrapper\Packages\CrystalReports\CRRedist2005_x86.msi和SDK\v2.0\BootStr ...
- 自定义组件---图片和文字实现ImageButton效果
1.效果图 2.自定义代码: <span style="font-family:Comic Sans MS;font-size:14px;">public class ...
- HDU 1142 A Walk Through the Forest(最短路+记忆化搜索)
A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...