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

  • Home
  • SEARCH
  • 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 1054041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:20:37+00:00 2026-05-16T17:20:37+00:00

An INSERT on a table triggers a stored proc where the following error occurs.

  • 0

An INSERT on a table triggers a stored proc where the following error occurs.

ERROR: column "targetedfamily" is of type boolean but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.
  Where: PL/pgSQL function "fn_family_audit" line 19 at SQL statement

And here’s the ERRING stored proc (notice that my attempt to fix the problem by doing CAST(NEW.targetedfamily AS BOOLEAN) does NOT seem to work)

CREATE OR REPLACE FUNCTION fn_family_audit() RETURNS TRIGGER AS $tr_family_audit$
    BEGIN
        --
        -- Create a row in family_audit to reflect the operation performed on family,
        -- make use of the special variable TG_OP to work out the operation.
        --
        IF (TG_OP = 'DELETE') THEN
            INSERT INTO public.family_audit values (
         DEFAULT, 'D', OLD.family_id, OLD.familyserialno, OLD.node_id, OLD.sourcetype, OLD.familyname,  
        OLD.familynamelocallang, OLD.hofname, OLD.hofnamelocallang, OLD.targetedfamily, OLD.homeless,
        OLD.landless, OLD.dependentonlabour, OLD.womenprimaryearner, OLD.landlinenumber, OLD.username , now());
            RETURN OLD;
        ELSIF (TG_OP = 'UPDATE') THEN
            INSERT INTO public.family_audit values(
         DEFAULT, 'U',NEW.family_id, NEW.familyserialno, NEW.node_id, NEW.sourcetype, NEW.familyname,   
        NEW.familynamelocallang, NEW.hofname, NEW.hofnamelocallang, NEW.targetedfamily, NEW.homeless,
        NEW.landless, NEW.dependentonlabour, NEW.womenprimaryearner, NEW.landlinenumber, NEW.username , now());
            RETURN NEW;
        ELSIF (TG_OP = 'INSERT') THEN
            INSERT INTO public.family_audit values(
         DEFAULT, 'I',NEW.family_id, NEW.familyserialno, NEW.node_id, NEW.sourcetype, NEW.familyname,   
        NEW.familynamelocallang, NEW.hofname, NEW.hofnamelocallang, CAST(NEW.targetedfamily AS BOOLEAN), NEW.homeless,
        NEW.landless, NEW.dependentonlabour, NEW.womenprimaryearner, NEW.landlinenumber, NEW.username , now());
            RETURN NEW;
        END IF;
        RETURN NULL; -- result is ignored since this is an AFTER trigger
    END;
$tr_family_audit$ LANGUAGE plpgsql;

Here’s the table definition

nucleus4=# \d family;
                                             Table "public.family"
       Column        |            Type             |                         Modifiers
---------------------+-----------------------------+------------------------------------------------------------
 family_id           | integer                     | not null default nextval('family_family_id_seq'::regclass)
 familyserialno      | integer                     | not null
 sourcetype          | character varying(20)       | not null
 familyname          | character varying(100)      |
 familynamelocallang | character varying(255)      |
 hofname             | character varying(100)      | not null
 hofnamelocallang    | character varying(255)      | not null
 targetedfamily      | boolean                     |
 homeless            | boolean                     |
 landless            | boolean                     |
 dependentonlabour   | boolean                     |
 womenprimaryearner  | boolean                     |
 landlinenumber      | character varying(20)       |
 username            | character varying(20)       | not null
 adddate             | timestamp without time zone | not null default now()
 updatedate          | timestamp without time zone | not null default now()
 node_id             | integer                     | not null
Indexes:
    "PK_family" PRIMARY KEY, btree (family_id)
    "family_idx" UNIQUE, btree (familyserialno, node_id)
Foreign-key constraints:
    "family_fk" FOREIGN KEY (node_id) REFERENCES hierarchynode_master(node_id)
Referenced by:
    TABLE "agriland" CONSTRAINT "FK_agriland_family" FOREIGN KEY (family_id) REFERENCES family(family_id) ON UPDATE RESTRICT ON DELETE RESTRICT
    TABLE "currentloans" CONSTRAINT "FK_currentloans_family" FOREIGN KEY (family_id) REFERENCES family(family_id) ON UPDATE RESTRICT ON DELETE RESTRICT
    TABLE "family_address" CONSTRAINT "FK_family_address_family" FOREIGN KEY (family_id) REFERENCES family(family_id) ON UPDATE RESTRICT ON DELETE RESTRICT
    TABLE "family_basic_info" CONSTRAINT "FK_family_basic_info_family" FOREIGN KEY (family_id) REFERENCES family(family_id) ON UPDATE RESTRICT ON DELETE RESTRICT
    TABLE "family_entitlement" CONSTRAINT "FK_family_entitlement_family" FOREIGN KEY (family_id) REFERENCES family(family_id) ON UPDATE RESTRICT ON DELETE RESTRICT
    TABLE "livestock" CONSTRAINT "FK_livestock_family" FOREIGN KEY (family_id) REFERENCES family(family_id) ON UPDATE RESTRICT ON DELETE RESTRICT
    TABLE "member" CONSTRAINT "FK_member_family" FOREIGN KEY (family_id) REFERENCES family(family_id) ON UPDATE RESTRICT ON DELETE RESTRICT
    TABLE "otherassets" CONSTRAINT "FK_otherassets_family" FOREIGN KEY (family_id) REFERENCES family(family_id) ON UPDATE RESTRICT ON DELETE RESTRICT
Triggers:
    tr_family_audit AFTER INSERT OR DELETE OR UPDATE ON family FOR EACH ROW EXECUTE PROCEDURE fn_family_audit()
    tr_family_updatedate BEFORE UPDATE ON family FOR EACH ROW EXECUTE PROCEDURE fn_modify_updatedate_column()


nucleus4=#

Here’s family_audit

nucleus4=# \d family_audit;
                                                Table "public.family_audit"
       Column        |            Type             |                               Mod
---------------------+-----------------------------+----------------------------------
 familyaudit_id      | integer                     | not null default nextval('family_
 operation           | character(1)                | not null
 family_id           | integer                     | not null
 familyserialno      | integer                     | not null
 sourcetype          | character varying(20)       | not null
 familyname          | character varying(100)      |
 familynamelocallang | character varying(255)      |
 hofname             | character varying(100)      | not null
 hofnamelocallang    | character varying(255)      | not null
 targetedfamily      | boolean                     |
 homeless            | boolean                     |
 landless            | boolean                     |
 dependentonlabour   | boolean                     |
 womenprimaryearner  | boolean                     |
 landlinenumber      | character varying(20)       |
 username            | character varying(20)       | not null
 adddate             | timestamp without time zone | not null default now()
 node_id             | integer                     | not null
Indexes:
    "PK_family_audit" PRIMARY KEY, btree (familyaudit_id)


nucleus4=#

Here’s the trigger

CREATE TRIGGER tr_family_audit
AFTER INSERT OR UPDATE OR DELETE ON public.family
    FOR EACH ROW EXECUTE PROCEDURE fn_family_audit();

I would appreciate any hints.

Thank you,

BR,
~A

  • 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-05-16T17:20:38+00:00Added an answer on May 16, 2026 at 5:20 pm

    Your problem is here:

    NEW.hofnamelocallang
    

    Your insert has one extra column (apparently NEW.node_id). Try changing your insert to:

    INSERT INTO public.family_audit values(
             DEFAULT, 'I',NEW.family_id, NEW.familyserialno, 
             NEW.sourcetype, NEW.familyname,   
             NEW.familynamelocallang, NEW.hofname, NEW.hofnamelocallang,
             NEW.targetedfamily, NEW.homeless,
             NEW.landless, NEW.dependentonlabour, NEW.womenprimaryearner, 
             NEW.landlinenumber, NEW.username , now()
    );
    

    The error you are getting is basically saying that you were trying to insert NEW.hofnamelocallang into targetedfamily column (which is boolean, not varchar) because of the extra column you were putting in the insert sentence.

    I would advice that, when you are performing an insert, for sanity reasons, always enumerate the columns you are putting values into. Something like this:

    insert into table foo
    (col1, col2, col3) -- column enumeration here
    values
    (1, 2, 3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to update my SQL lite database with the native update-method of

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.