遇到的问题是:
bdb支持insert or replace into 表名 values(...)这种用法,pgsql不支持
查看资料找到了自定义函数的办法:
CREATE FUNCTION update_online(uid INT,online TEXT,vosId TEXT,vosCheckout TEXT)
RETURNS SETOF INT AS $$
UPDATE tb_online SET online = $online WHERE vosId = $vosId RETURNING $uid
$$ LANGUAGE sql;
CREATE FUNCTION upsert_online(k INT,v TEXT)
RETURNS VOID AS $$
INSERT INTO foo
SELECT $1,$2
WHERE NOT EXISTS (SELECT update_foo($1,$2))
$$ LANGUAGE sql;
http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-UPSERT-EXAMPLE
stackoverflow讨论地址:
http://stackoverflow.com/questions/1109061/insert-on-duplicate-update-postgresql