无法在LibreOffice Base中添加查询记录 - 违反唯一索引

时间:2015-10-21 12:54:03

标签: database libreoffice

我正在尝试将记录添加到一个表,该表链接到我不想修改的其他表。当我尝试向相关表中添加记录时,会显示一条错误消息:

Error inserting the new record.
Violation of the unique index "<unique index>":
duplicate values for columns "xxx", "yyyy" in statement [INSERT INTO "table"("xxx","yyyy")VALUES(?,?)].

错误消息是正确的,因为该表具有由两个字段组成的唯一索引。但是,在第一个实例中,我不希望将记录添加到该表中,因为它仅用作我正在添加或修改记录的主表的查找表。

错误的表确实有三个键。一个主要是自动递增,第二个唯一键包含两个字段,第三个外部查找键不唯一。

我不确定这里发生了什么,但我认为这与包含两个字段的索引有关。

SELECT DISTINCT "Futures_Orders"."Date",
"Futures_Orders"."Symbol","Futures_Orders"."Contract_Mth",
"Futures_Orders"."Send_To_Broker",
"Futures_Orders"."Order-Id", 
"Futures_Orders"."Broker","Futures_Orders"."Order_Action",
"Futures_Orders"."No_Contracts",
"Futures_Orders"."Order_Price", 
"Futures_Orders"."Trade_Type",
CASE "Futures_Orders"."Order_Action" 
   WHEN 'b' THEN 's' 
ELSE 'b' 
END "If_Done_Action",
"Futures_Orders"."If_Done_Price", 
"Futures_Orders"."No_Contracts" * ( 
CASE "Contract_Details"."USIntRates" 
   WHEN 'n' THEN ABS( "Futures_Orders"."Order_Price"
      - "Futures_Orders"."If_Done_Price" ) / 
      "Contract_Details"."MinTick"
   ELSE ABS(ABS(TRUNCATE("Futures_Orders"."Order_Price",
       0)-TRUNCATE("Futures_Orders"."If_Done_Price",
          0))*"Contract_Details"."MinTick" -
       CASE 
          WHEN "Contract_Details"."Symbol" 
                   IN ( 'FV', 'TU' ) THEN 400 
          ELSE 200 
       END * 
       ABS("Futures_Orders"."Order_Price" -
         TRUNCATE("Futures_Orders"."Order_Price", 0)-
         "Futures_Orders"."If_Done_Price" + TRUNCATE(
         "Futures_Orders"."If_Done_Price", 0 )))
END 
* "Contract_Details"."MinTickVal" / "FX_Rates"."Rate" +
CASE
   WHEN "Broker_Commissions"."Commission_AUD" +
      "Broker_Commissions"."Commission" = 0
      THEN "Broker"."Commission"
   ELSE "Broker_Commissions"."Commission_AUD" +
      "Broker_Commissions"."Commission" / "FX_Rates"."Rate"
END
* 2) "Risk",
"Contract_Details"."Symbol",  "Contract_Details"."Currency",
"FX_Rates"."Code", "Broker"."Broker",
"Broker_Commissions"."Symbol", "Broker_Commissions"."Broker",
"Broker_Commissions"."ID"
FROM "Futures_Orders", "Contract_Details", "FX_Rates", "Broker",
"Broker_Commissions" WHERE "Futures_Orders"."Symbol" =
"Contract_Details"."Symbol" AND "Contract_Details"."Currency" =
"FX_Rates"."Code" AND "Futures_Orders"."Broker" = "Broker"."Broker"
AND "Futures_Orders"."Broker" = "Broker_Commissions"."Broker" AND
"Futures_Orders"."Symbol" = "Broker_Commissions"."Symbol"

1 个答案:

答案 0 :(得分:1)

问题出在我的密钥和我的选择语句中。我对关系进行了一些小改动,并将select语句的最后一部分改为如下,一切都很好。谢谢你的帮助。当我正在阅读别的东西时,我感觉到这是一个问题。

FROM "Futures_Orders", "Contract_Details", "FX_Rates", "Broker",
"Broker_Commissions" WHERE "Futures_Orders"."Symbol" =
"Contract_Details"."Symbol" AND "Contract_Details"."Currency" =
"FX_Rates"."Code" AND "Futures_Orders"."Broker" = "Broker"."Broker"
AND "Broker"."Broker" = "Broker_Commissions"."Broker" AND
"Contract_Details"."Symbol" = "Broker_Commissions"."Symbol"