希望一雙新鮮的眼睛能夠發現我做錯了什麼,或者指出我可以在哪裏進一步調查我的問題。我正在創建一個包含作爲json字符串傳遞的參數的函數。Postgresql - json操作數無法解釋的語法錯誤
使用json運算符->
訪問json中的數據元素會報告一個令我困惑的語法錯誤。這裏是我的功能(簡述):
CREATE OR REPLACE FUNCTION createUser(
email_f character varying(50),
mobile_f integer,
salt_f character(16),
hash_f character(16),
encryption_f smallint,
iterations_f smallint,
fnam_f character varying(16),
lnam_f character varying(16),
nickname_f character varying(16),
fb_f json
) RETURNS json AS $$
/* Example /me response from FB
{
id: "101...", email: "[email protected]", verified: true,
name: "test testlast", first_name: "test", last_name: "testlast", gender: "male",
link: "https://www.facebook.com/app_scoped_user_id/101.../",
locale: "en_US", timezone: -5, updated_time: "2014-07-01T14:48:27+0000"
}
*/
BEGIN
IF fnam_f IS NULL THEN
SET fnam_f = fb_f->'first_name';
SET lnam_f = fb_f->'last_name';
END IF;
INSERT INTO users (email,mobile,salt,hash,encryption,iteration,username,fbid)
SELECT email_f,mobile_f,salt_f,hash_f,encryption_f,iteration_f,nickname_f,null
RETURNING row_to_json(row(*));
END;
$$ LANGUAGE 'plpgsql';
運行該查詢返回一個語法錯誤:
ERROR: syntax error at or near "->"
LINE 24: SET fnam_f = fb_f->'first_name';
我覺得這是令人困惑,因爲我似乎被正確使用JSON操作根據文檔:http://www.postgresql.org/docs/9.3/static/functions-json.html
感謝
發佈'select version()' –