swift - 阿拉莫菲尔后下一个瓦尔

标签 swift postgresql alamofire

如何在 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/

相关文章:

postgresql - 如何减少具有有序结果的 postgresql IN 查询的索引扫描时间?

ios - Alamofire HTTPS 请求不适用于该网站

ios - Alamofire 与谷歌地理编码 API

ios - 快速错误 : NSInternalInconsistencyException, 'Upload attempting to execute on non main queue! Only on the main queue.'

ios - 暂停直到 CLLocation 不为零

swift - 如何从 Swift 运行 JXA?

ios - CocoaLumberjack with Swift - 调用预处理器宏

postgresql - 检索聚合和日期运算符的附加列

sql - 将数据插入多个表 Postgres

ios - 图片 URL 不缓存