我的问题与this question有关。 我想切换一个表的两个id,它们被定义为主键。
但遗憾的是,我想要切换id的表已经创建,主键约束未设置为deferrable
。
我尝试使用以下语句将其设置为可延迟:
alter table table_name alter constraint primary_key_name_pkey deferrable;
得到一个错误:
constraint "primary_key_name_pkey" of relation "table_name" is not a foreign key constraint
有没有办法在创建后将主键约束设置为可推迟?
感谢您的帮助。
答案 0 :(得分:0)
如PostgreSQL源代码中所述:
package controllers;
import models.Sysuser;
import models.DataI;
import models.DataII;
import play.mvc.Controller;
import play.mvc.Result;
import play.mvc.Security;
import views.html.sitemap.index;
import javax.inject.*;
import java.util.concurrent.CompletionStage;
import play.libs.concurrent.HttpExecutionContext;
import static java.util.concurrent.CompletableFuture.supplyAsync;
import io.ebean.*;
import play.Logger;
import java.util.List;
import play.libs.Json;
import java.util.*;
import java.util.stream.*;
@Security.Authenticated(Secured.class)
public class SiteMap extends Controller {
private final HttpExecutionContext httpExecutionContext;
private static final Logger.ALogger logger = Logger.of(SiteMap.class);
@Inject
public SiteMap(HttpExecutionContext httpExecutionContext) {
this.httpExecutionContext = httpExecutionContext;
}
public CompletionStage<Result> index() {
return supplyAsync(() -> {
return ok(views.html.sitemap.index.render(Sysuser.findByUserName(request().username()), QueryI(), QueryII() ));
}, httpExecutionContext.current());
}
/**
* Custom Query 1
*/
public List<DataI> QueryI() {
final String sql = "SELECT sysuser_id, role_id "
+"from sysuser_role "
+"where sysuser_id = '1' "
+"and role_id in ('1','2','3','4','5') ";
final RawSql rawSql = RawSqlBuilder.parse(sql).create();
Query<DataI> query = Ebean.find(DataI.class);
query.setRawSql(rawSql);
List<DataI> L = query.findList();
return(L);
}
/**
* Custom Query 2
*/
public List<DataII> QueryII() {
final String sql = "SELECT sysuser.name, sysuser.active, department.description "
+"from sysuser "
+"left join department on department.id = sysuser.department_id "
+"where sysuser.id = '2' ";
final RawSql rawSql = RawSqlBuilder.parse(sql).create();
Query<DataII> query = Ebean.find(DataII.class);
query.setRawSql(rawSql);
List<DataII> L = query.findList();
return(L);
}
}
来源:https://github.com/postgres/postgres/blob/master/src/backend/commands/tablecmds.c#L9557
因此,即使使用Pg12,也是不可能的。