create or replace function test_hstore() returns void as
$$
declare
_my_cursor(p_co_id text) for
select * from crm_db.ht_co_addon where co_id = p_co_id;
_row record;
_addon_id2co_addon_id_h hstore;
_sms_ao text := 'SMS_AO';
begin
for _row in _my_cursor('000000000666') loop
if _addon_id2co_addon_id_h is null then
_addon_id2co_addon_id_h := (_row.addon_id||'=>'||_row.co_addon_id)::hstore;
else
_addon_id2co_addon_id_h := _addon_id2co_addon_id_h || (_row.addon_id||'=>'||_row.co_addon_id)::hstore;
end if;
end loop;
raise notice 'SMS_AO: %', _addon_id2co_addon_id_h->_sms_ao;
for _row in select * from each(_addon_id2co_addon_id_h) loop
raise notice 'h: %=>%', _row.key, _row.value;
end loop;
end;
$$ language plpgsql security definer;
Thursday, March 26, 2015
PostgreSQL: hstore or a perl like hash table
Labels:
postgresql