Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PostgreSQL:Column";螃蟹“身份证”;多次指定_Postgresql_Inner Join - Fatal编程技术网

PostgreSQL:Column";螃蟹“身份证”;多次指定

PostgreSQL:Column";螃蟹“身份证”;多次指定,postgresql,inner-join,Postgresql,Inner Join,通过PostgreSQL调用 CREATE TABLE condor_xrootd AS SELECT * FROM condor INNER JOIN xrootd_ext ON ( xrootd_ext.CRAB_Id = condor.CRAB_Id AND REPLACE(condor.CRAB_ReqName, '_', ':') = xrootd_ext.CRAB_ReqName ); 我得到了错误 $ psql condor -f ./sql/inne

通过PostgreSQL调用

CREATE TABLE condor_xrootd AS
       SELECT * FROM condor INNER JOIN xrootd_ext
       ON (
xrootd_ext.CRAB_Id = condor.CRAB_Id AND
REPLACE(condor.CRAB_ReqName, '_', ':') = xrootd_ext.CRAB_ReqName
);
我得到了错误

$ psql condor -f ./sql/inner_join.sql 
psql:./sql/inner_join.sql:6: ERROR:  column "crab_id" specified more than once
这是可以理解的,因为每个表都有一个Crab_Id列。我希望能够在不必指定列的情况下进行内部联接,因为两个表中总共有大约400列

请让我知道我是否可以在不单独列出列的情况下以某种方式消除此错误

编辑:


我忘了提到速度和稳定性在这里是至关重要的,因为我的加入可能需要几天时间。

您从一个由两个表组成的结果集创建表。您的错误是,
crab\u id
列存在于
condor
xrootd\u ext
表中,Postgresql不知道应该选择哪个

create table condor_xrootd as
select *
from
    condor
    inner join
    xrootd_ext using (crab_id)
where replace(condor.crab_reqname, '_', ':') = xrootd_ext.crab_reqname
您应该指定要为其创建表的字段。像这样:

CREATE TABLE condor_xrootd AS
       SELECT
          condor.*, -- here we take all fields from condor table
          xrootd_ext.crab_reqName -- here we take crab_reqName field from xrootd_ext
       FROM condor INNER JOIN xrootd_ext
       ON (
xrootd_ext.CRAB_Id = condor.CRAB_Id AND
REPLACE(condor.CRAB_ReqName, '_', ':') = xrootd_ext.CRAB_ReqName
);

您可以从由两个表组成的结果集创建表。您的错误是,
crab\u id
列存在于
condor
xrootd\u ext
表中,Postgresql不知道应该选择哪个

您应该指定要为其创建表的字段。像这样:

CREATE TABLE condor_xrootd AS
       SELECT
          condor.*, -- here we take all fields from condor table
          xrootd_ext.crab_reqName -- here we take crab_reqName field from xrootd_ext
       FROM condor INNER JOIN xrootd_ext
       ON (
xrootd_ext.CRAB_Id = condor.CRAB_Id AND
REPLACE(condor.CRAB_ReqName, '_', ':') = xrootd_ext.CRAB_ReqName
);

对于连接,当连接具有相同名称的列时,可以尝试使用USING子句而不是ON,例如condor internal join xrootd_ext USING(CRAB_Id)。使用此选项时,生成的联接应该只有一个正在联接的列的实例。在PostreSQL中可能有效,也可能无效,但您可以尝试一下。看看这个问题:我相信它回答了您的问题。对于连接,在使用相同名称连接列时,您可以尝试使用USING子句而不是ON,例如condor Internal join xrootd_ext USING(CRAB_Id)。使用此选项时,生成的联接应该只有一个正在联接的列的实例。在PostreSQL中可能有效,也可能无效,但您可以尝试一下。看看这个问题:我相信它回答了您的问题。Clodoaldo Neto的答案似乎有效,而且更简单,因为我需要所有XRootD列。我关心WHERE条款。你知道哪个更快吗?或者你能证明它吗?应该没有任何性能差异。我想解释会证明这一点。Clodoaldo Neto的答案似乎有效,而且更简单,因为我需要所有的XRootD列。我关心WHERE条款。你知道哪个更快吗?或者你能证明它吗?应该没有任何性能差异。我想解释会证明这一点。所以,用对你更好的答案。你知道你的答案会比斯塔斯更快吗?亚拉诺夫的?艾丹可能和你知道的一样,你的答案会比斯塔斯更快吗?亚拉诺夫的?艾丹可能也一样