code: func (agp *AuthGroupPermission) Upsert(db XODB) error {
  	var err error
  
  	// if already exist, bail
  	if agp._exists {
  		return errors.New("insert failed: already exists")
  	}
  
  	// sql query
  	const sqlstr = `INSERT INTO public.auth_group_permissions (` +
  		`id, group_id, permission_id` +
  		`) VALUES (` +
  		`$1, $2, $3` +
  		`) ON CONFLICT (id) DO UPDATE SET (` +
  		`id, group_id, permission_id` +
  		`) = (` +
  		`EXCLUDED.id, EXCLUDED.group_id, EXCLUDED.permission_id` +
  		`)`
  
  	// run query
  	XOLog(sqlstr, agp.ID, agp.GroupID, agp.PermissionID)
  	_, err = db.Exec(sqlstr, agp.ID, agp.GroupID, agp.PermissionID)
  	if err != nil {
  		return err
  	}
  
  	// set existence
  	agp._exists = true
  
  	return nil
  }
docs: // Upsert performs an upsert for AuthGroupPermission.
  //
  // NOTE: PostgreSQL 9.5+ only