如何在 PostgreSQL 中发布 nexval 使用 Alamofire? 我有具有下一个结构的 REST API:
["ID": int,
"Date": Datetime,
"Boolean": Boolean,
"String": String]
ID 是序列。我怎样才能发布它?在 PostgreSQL 中,我可以通过下一个请求插入表中:
insert into "Table" values (nextval('"Table_ID_seq"'::regclass),'2016-02-24 12:33:37 + 0000','1','My string')
我在 POST 时遇到问题:nextval('"Table_ID_seq"'::regclass)
如果我写一些 Int 值而不是 nextval('"Table_ID_seq"'::regclass)
,则一切正常。
我的参数:
let now = NSDate();
let parameters = [
"ID": "nextval(\'\"Table_ID_seq\"\' ::regclass)",
"Boolean": "TRUE",
"Datetime": "\(now)",
"String": "My string"
];
Alamofire.request(.POST, URL, parameters: parameters as? [String : AnyObject], encoding: .JSON)
最佳答案
我解决了这个问题。在 PostgreSQL 的属性字段中的默认值中输入:nextval('"Table_ID_seq"'::regclass)
然后创建没有ID的POST方法。
关于swift - 阿拉莫菲尔后下一个瓦尔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35626068/