我们可以在1个查询postgresql中更新两个表

时间:2016-10-04 05:32:17

标签: mysql postgresql

我使用postgres作为我的数据库并有2个表

accounts
id | name | status


accountOwner
account_id | user_id 

我有user_id(accountOwner表)和状态(帐户表)根据我的accountid进行更新。是否可以更新1个查询中的两个表?我尝试了以下

UPDATE accounts,accountOwner SET accounts.status='active', accountOwner.user_id=3 WHERE  accounts.id=accountOwner.account_id AND accountOwner.account_id = 1;

1 个答案:

答案 0 :(得分:1)

不,您不能一次更新两个表。 The documentation说:

  

更新 - 更新

的行

但是,您可以使用 FROM 子句,例如:

convenience init?(userInfo: [NSObject: AnyObject]) {
    guard let statusString = userInfo[ConnectionMessage.StatusKey] as? String else {
        return nil
    }
    guard let status = ConnectionStatus(string: statusString) else {
        return nil
    }

    guard let connectionId = userInfo[ConnectionMessage.ConnectionIdKey]?.longLongValue else {
        return nil
    }

    var ssid = ""

    if let newSsid = userInfo[ConnectionMessage.SSIDKey] as? String {
        ssid = newSsid
    }

    var password = ""
    if let pw = userInfo[ConnectionMessage.PasswordKey] as? String {
        password = pw
    }

    let buyerName = userInfo[ConnectionMessage.BuyerNameKey] as? String

    self.init(status: status, connectionId: connectionId, ssid: ssid, password: password, buyerName: buyerName)
}