我有一个PostgreSQL表定义如下:
Table "public.dm_metadata"
Column | Type | Modifiers
------------+-----------------------------+------------------------
id | character varying(60) | not null
insertedat | timestamp without time zone | not null default now()
metadata | hstore |
Indexes:
"dm_metadata_pkey" PRIMARY KEY, btree (id, insertedat)
"dm_metadata_metadata_idx" gist (metadata)
有人能举例说明如何使用libpqxx和预编译语句将INSERT和SELECT数据插入此表吗?
具体来说,我对以下查询感兴趣:
INSERT INTO dm_metadata(id, metadata) VALUES ('werwer', '"a" => 1234');
INSERT INTO dm_metadata(id, metadata) VALUES ('werwer', '"a" => 1234, "b" => "hello"');
SELECT metadata FROM dm_metadata WHERE metadata @> '"a"=>1234';
SELECT metadata FROM dm_metadata WHERE metadata @> '"a"=>1234,"b"=>"hello"';