code: def update_sql(table, filter, updates):
      '''
      >>> update_sql('tbl', {'foo': 'a', 'bar': 1}, {'bar': 2, 'baz': 'b'})
      ('UPDATE tbl SET bar=$1, baz=$2 WHERE bar=$3 AND foo=$4', [2, 'b', 1, 'a'])
      '''
      where_keys, where_vals = _split_dict(filter)
      up_keys, up_vals = _split_dict(updates)
      changes = _pairs(up_keys, sep=', ')
      where = _pairs(where_keys, start=len(up_keys) + 1)
      sql = 'UPDATE {} SET {} WHERE {}'.format(
          table, changes, where)
      return sql, up_vals + where_valf update_sql(table, filter, updates):
      '''
      >>> update_sql('tbl', {'foo': 'a', 'bar': 1}, {'bar': 2, 'baz': 'b'})
      ('UPDATE tbl SET bar=$1, baz=$2 WHERE bar=$3 AND foo=$4', [2, 'b', 1, 'a'])
      '''
      where_keys, where_vals = _split_dict(filter)
      up_keys, up_vals = _split_dict(updates)
      changes = _pairs(up_keys, sep=', ')
      where = _pairs(where_keys, start=len(up_keys) + 1)
      sql = 'UPDATE {} SET {} WHERE {}'.format(
          table, changes, where)
      return sql, up_vals + where_vals
docs: >>> update_sql('tbl', {'foo': 'a', 'bar': 1}, {'bar': 2, 'baz': 'b'})
      ('UPDATE tbl SET bar=$1, baz=$2 WHERE bar=$3 AND foo=$4', [2, 'b', 1, 'a'])