0

ユーザーがデータベーステーブルの既存の情報を自動的に挿入または更新できるようにする挿入ルールと更新ルールを使用してpostgresqlテーブルを作成しようとしています。テーブルを作成するためにデータベース内でSQLクエリを実行しようとすると、このエラーが発生し続けます。PostgreSQL9.1のドキュメント手順に従おうとしました。主キーの1つについて、式を書き直す必要があるというエラーが表示され続けます。誰かがこのスクリプトを見て、私を助けてくれませんか。あなたの最も価値のある貢献に感謝します!

これが私のSQLスクリプトです

 CREATE TABLE fieldtally1
  (fieldtally1_id serial NOT NULL,
  pipeno character varying,
  wthick real,
  heatno1 character varying(32),
  pipeno2 character varying(32),
  heatno2 character varying(32),
  Djointno character varying(32),
  ContractorNo character varying(32),
  measuredlength double precision,
  serialno character varying(32),
  CoatingType character varying(32),
  coatingno character varying(32),
  mnfcno character varying(32),
  FactoryLength double precision,
  pipeod_in numeric,
  pipeod_mm numeric,
  pipeweight double precision,
  pipegrade numeric,
  loadtally numeric,
  dateweilded date,
  datereceived date,
  dataenteredby character varying(50),
  deliveryno character varying(50),
  manufacturer character varying(50),
  Remarks character varying(100),
  ManualUser character varying(100),
  log_when timestamp,
  CONSTRAINT fieldtally1_pkey PRIMARY KEY (fieldtally1_id, pipeno)
  );
  Create rule fieldtally1_ins as on INSERT to fieldtally1
  Do Instead
  Insert into fieldtally1 values (
                New.pipeno,
                New.wthick,
                New.heatno1,
                New.pipeno2,
                New.heatno2,
                New.Djointno,
                New.ContractorNo,
                New.measuredlength,
                New.serialno,
                New.coatingtype,
                New.coatingno,
                New.mnfcno,
                New.factorylength,
                New.pipeod_in,
                New.pipeod_mm,
                New.pipeweight,
                New.pipegrade,
                New.ManualUser, 
                current_timestamp
                );

CREATE RULE fieldtally1_upd AS ON UPDATE TO fieldtally1
    DO INSTEAD
    UPDATE fieldtally1
    SET PIPENO = New.pipeno,
    wthick = New.wthick,
    heatno1 = New.heatno1,
    pipeno2 = New.pipeno2,
    heatno2 = New.heatno2,
    Djointno = New.Djointno,
    ContractorNo = New.ContractorNo,
    measuredlength = New.measuredlength,
    New.serialno = New.serialno,
    coatingtype = New.coatingtype,
    coatingno = New.coatingno,
    mnfcno = New.mnfcno,
    factorylength = New.factorylength,
    pipeod_in = New.pipeod_in,
    pipeod_mm = New.pipeod_mm,
    pipeweight = New.pipeweight,
    pipegrade =  New.pipegrade,
    ManualUser = New.ManualUser 
    WHERE pipeno = OLD.pipeno;      

CREATE RULE fieldtally1_del AS ON DELETE TO fieldtally1
    DO INSTEAD
    DELETE FROM fieldtally1
     WHERE pipeno = OLD.pipeno;

スクリプトを実行したときに発生するエラーは次のとおりです

注意:CREATE TABLEは、シリアル列「fieldtally1.fieldtally1_id」に対して暗黙のシーケンス「fieldtally1_fieldtally1_id_seq」を作成します。注意:CREATE TABLE / PRIMARY KEYは、テーブル「fieldtally1」に対して暗黙のインデックス「fieldtally1_pkey」を作成します。は文字の種類が異なります行34:New.pipeno、^ヒント:式を書き直すかキャストする必要があります。

***エラー** *

エラー:列 "fieldtally1_id"は整数型ですが、式はSQL状態が変化する文字型です:42804ヒント:式を書き直すかキャストする必要があります。文字:1024

4

2 に答える 2

1

挿入が列と正確に一致しない場合は、それらを指定する必要があります。アップデートには「新規」が含まれています。serialnoの左側:これはhttp://sqlfiddle.com/#!1/c9ef3/1/0で機能します

CREATE TABLE fieldtally
(fieldtally_id serial NOT NULL primary key,
  pipeno character varying,
  wthick real,
  heatno1 character varying(32),
  pipeno2 character varying(32),
  heatno2 character varying(32),
  Djointno character varying(32),
  ContractorNo character varying(32),
  measuredlength double precision,
  serialno character varying(32),
  CoatingType character varying(32),
  coatingno character varying(32),
  mnfcno character varying(32),
  FactoryLength double precision,
  pipeod_in numeric,
  pipeod_mm numeric,
  pipeweight double precision,
  pipegrade numeric,
  loadtally numeric,
  dateweilded date,
  datereceived date,
  dataenteredby character varying(50),
  deliveryno character varying(50),
  manufacturer character varying(50),
  Remarks character varying(100),
  ManualUser text,
  log_when timestamp
  );
  Create rule fieldtally_ins as on INSERT to fieldtally
  Do Instead
  Insert into fieldtally (pipeno, wthick, heatno1, pipeno2, heatno2, djointno, contractorno, measuredlength, serialno, coatingtype, coatingno,
                         mnfcno, factorylength, pipeod_in, pipeod_mm, pipeweight, pipegrade, manualuser, log_when) values (
                New.pipeno,
                New.wthick,
                New.heatno1,
                New.pipeno2,
                New.heatno2,
                New.Djointno,
                New.ContractorNo,
                New.measuredlength,
                New.serialno,
                New.coatingtype,
                New.coatingno,
                New.mnfcno,
                New.factorylength,
                New.pipeod_in,
                New.pipeod_mm,
                New.pipeweight,
                New.pipegrade,
                New.ManualUser, 
                current_timestamp
                );

CREATE RULE fieldtally_upd AS ON UPDATE TO fieldtally
    DO INSTEAD
    UPDATE fieldtally
    SET PIPENO = New.pipeno,
    wthick = New.wthick,
    heatno1 = New.heatno1,
    pipeno2 = New.pipeno2,
    heatno2 = New.heatno2,
    Djointno = New.Djointno,
    ContractorNo = New.ContractorNo,
    measuredlength = New.measuredlength,
    serialno = New.serialno,
    coatingtype = New.coatingtype,
    coatingno = New.coatingno,
    mnfcno = New.mnfcno,
    factorylength = New.factorylength,
    pipeod_in = New.pipeod_in,
    pipeod_mm = New.pipeod_mm,
    pipeweight = New.pipeweight,
    pipegrade =  New.pipegrade,
    ManualUser = New.ManualUser 
    WHERE pipeno = OLD.pipeno;      

CREATE RULE fieldtally_del AS ON DELETE TO fieldtally
    DO INSTEAD
    DELETE FROM fieldtally
     WHERE pipeno = OLD.pipeno;
于 2012-10-26T21:15:04.490 に答える
-2

ユーザーGO-SQLは最後の実行前に検証をチェックしません

CREATE TABLE fieldtally
    (fieldtally_id serial NOT NULL primary key,
      pipeno character varying,
      wthick real,
      heatno1 character varying(32),
      pipeno2 character varying(32),
      heatno2 character varying(32),
      Djointno character varying(32),
      ContractorNo character varying(32),
      measuredlength double precision,
      serialno character varying(32),
      CoatingType character varying(32),
      coatingno character varying(32),
      mnfcno character varying(32),
      FactoryLength double precision,
      pipeod_in numeric,
      pipeod_mm numeric,
      pipeweight double precision,
      pipegrade numeric,
      loadtally numeric,
      dateweilded date,
      datereceived date,
      dataenteredby character varying(50),
      deliveryno character varying(50),
      manufacturer character varying(50),
      Remarks character varying(100),
      ManualUser text,
      log_when timestamp
      );
GO
      Create rule fieldtally_ins as on INSERT to fieldtally
      Do Instead
      Insert into fieldtally values (
                    New.pipeno,
                    New.wthick,
                    New.heatno1,
                    New.pipeno2,
                    New.heatno2,
                    New.Djointno,
                    New.ContractorNo,
                    New.measuredlength,
                    New.serialno,
                    New.coatingtype,
                    New.coatingno,
                    New.mnfcno,
                    New.factorylength,
                    New.pipeod_in,
                    New.pipeod_mm,
                    New.pipeweight,
                    New.pipegrade,
                    New.ManualUser, 
                    current_timestamp
                    );
GO
        CREATE RULE fieldtally_upd AS ON UPDATE TO fieldtally
            DO INSTEAD
            UPDATE fieldtally
            SET PIPENO = New.pipeno,
            wthick = New.wthick,
            heatno1 = New.heatno1,
            pipeno2 = New.pipeno2,
            heatno2 = New.heatno2,
            Djointno = New.Djointno,
            ContractorNo = New.ContractorNo,
            measuredlength = New.measuredlength,
            New.serialno = New.serialno,
            coatingtype = New.coatingtype,
            coatingno = New.coatingno,
            mnfcno = New.mnfcno,
            factorylength = New.factorylength,
            pipeod_in = New.pipeod_in,
            pipeod_mm = New.pipeod_mm,
            pipeweight = New.pipeweight,
            pipegrade =  New.pipegrade,
            ManualUser = New.ManualUser 
            WHERE pipeno = OLD.pipeno;      
    GO
        CREATE RULE fieldtally_del AS ON DELETE TO fieldtally
            DO INSTEAD
            DELETE FROM fieldtally
             WHERE pipeno = OLD.pipeno;
于 2012-10-26T21:10:33.563 に答える