Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8772023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:56:15+00:00 2026-06-13T17:56:15+00:00

I am trying to create a postgresql table with insert and update rules that

  • 0

I am trying to create a postgresql table with insert and update rules that can make it possible for the users to automatically insert information or update the the existing information on the database table. When i try to run the SQL query within the database inorder to create the table, i keep getting this error. I tried to follow the documentaion steps in PostgreSQL 9.1. It keeps giving me error on the expression for one of my primary keys stating that i need to be re-write it . Please can somebody look at this script and help me out. Thanks for your most valued contributions!

Here is my SQL script

 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;

Here is the error i get when i run the script

NOTICE: CREATE TABLE will create implicit sequence “fieldtally1_fieldtally1_id_seq” for serial column
“fieldtally1.fieldtally1_id” NOTICE: CREATE TABLE / PRIMARY KEY will
create implicit index “fieldtally1_pkey” for table “fieldtally1”
ERROR: column “fieldtally1_id” is of type integer but expression is
of type character varying LINE 34: New.pipeno,
^ HINT: You will need to rewrite or cast the expression.

*** Error ***

ERROR: column “fieldtally1_id” is of type integer but expression is of
type character varying SQL state: 42804 Hint: You will need to rewrite
or cast the expression. Character: 1024

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:56:16+00:00Added an answer on June 13, 2026 at 5:56 pm

    If your insert doesn’t match the column exactly, you need to specify them. Your update includes a “new.” on the left hand side of serialno: This works in 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;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create crosstab queries in PostgreSQL such that it automatically generates
I am trying to make a method for a class that will automatically insert
I am trying to create a pivot table type view in postgresql and am
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying to create a database table using PostgreSQL but I am unable
I'm trying to create a function to insert data into a table. The query
I'm trying to create a function which references a temporary table in PostgreSQL 8.4.
I am trying to create a function that does this: drop table t_rv_openitem; select
I'm a postgresql user and I'm trying to follow this : http://www.postgresql.org/docs/current/interactive/sql-createtrigger.html CREATE TRIGGER
Trying to create a macro which can be used for print debug messages when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.