下面是用於與hstore和PG-8.4爲Debian應答的步驟。
1)如果尚未安裝,安裝的contrib包
# apt-get install postgresql-contrib-8.4
2)在相關數據庫
$ psql -U postgres -d dbname
# \i /usr/share/postgresql/8.4/contrib/hstore.sql
2之二)如果未安裝PLPGSQL語言,安裝它安裝hstore(仍在psql中作爲postgres用戶)
# CREATE LANGUAGE plpgsql;
3)創建以hstore爲函數輸入。下面是plpgsql中的一個示例,其中列舉了鍵和值:
CREATE OR REPLACE function enum_hstore(in_h hstore) returns void
as $$
declare
kv record;
begin
for kv in select * from (select (each(in_h)).*) as f(k,v) loop
raise notice 'key=%,value=%',kv.k,kv.v;
end loop;
end
$$ language plpgsql;
4)調用函數。由於鍵和值是文本類型,因此可能需要將文本中的非文字條目轉換爲問題中的current_timestamp調用。例如:
select enum_hstore(
hstore('c',current_timestamp::text) ||
'a=>2,b=>5'::hstore
);
結果從上面的功能期待:
NOTICE: key=a,value=2
NOTICE: key=b,value=5
NOTICE: key=c,value=2012-04-08 16:12:59.410056+02
你的意思是你想hstore值傳遞到函數? http://www.postgresql.org/docs/9.0/static/hstore.html – Edmund 2012-04-08 09:17:32
嗯不錯的選擇但我越來越'錯誤:類型「hstore」不存在'我正在使用8.4 – 2012-04-08 10:18:43
啊,我認爲這只是當時的一個貢獻模塊。應該工作,如果你安裝它。 http://www.postgresql.org/docs/8.4/static/hstore.html – Edmund 2012-04-08 10:29:51