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 8722143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:20:37+00:00 2026-06-13T07:20:37+00:00

I have a table like: CREATE TABLE test( id integer not null default nextval(‘test_id_seq’::regclass),

  • 0

I have a table like:

CREATE TABLE test(
id integer not null default nextval('test_id_seq'::regclass),
client_name_id integer not null
);

Foreign-key constraints:

"test_client_name_id_fkey" FOREIGN KEY (client_name_id) REFERENCES company(id) DEFERRABLE INITIALLY DEFERRED

and company table:

CREATE TABLE company(
id integer not null default nextval('company_id_seq'::regclass),
company_name character varying(64) not null
)

Now I have trigger on test table which fetch id from company table using provided value client_name_id which is string by matching it with company_name. but when I insert record PostgreSQL return error that client_name_id is string and int required which is true.

How can I tell PostgreSQL not to verify inserted row as I have taken care of it in my triggers.

  • 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-13T07:20:39+00:00Added an answer on June 13, 2026 at 7:20 am

    What you are trying to do is very unorthodox. Are you sure, this is what you want? Of course, you cant enter a string (with non-digits) into an integer column. No surprise there, right? If you want to enter the text instead, you’d have to add a text column instead – with a fk-constraint to company(company_name) if you want to match your current layout.

    ALTER TABLE test ALTER DROP COLUMN client_name_id; -- drops fk constraint, too
    ALTER TABLE test ADD COLUMN client_name REFERENCES company(company_name);
    

    You would need a UNIQUE constraint on company.company_name to allow this.

    However, I would advise to rethink your approach. Your table layout seems proper as it is. The trigger is the unconventional element. Normally, you would reference the primary key, just like you have it now. No trigger needed. To get the company name, you would join the table in a SELECT:

    SELECT *
    FROM   test t
    JOIN   company c ON t.client_name_id = c.id;
    

    Also, these non-standard modifiers should only be there if you need them: DEFERRABLE INITIALLY DEFERRED. Like, when you have to enter values in table test before you enter the referenced values in table company (in the same transaction).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I have the following table: CREATE TABLE test ( id integer NOT NULL,
I have a table like this: create table `test` ( `id` bigint(20) NOT NULL
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
If I have a table like CREATE TABLE [FooTable]( [foo] [varchar](50) NOT NULL, [foo_boo]
I have a table like this: CREATE TABLE book_info ( book_id VARCHAR(32) not null,
I have Created a table like CREATE TABLE [dbo].[tab1]( [Id] [int] NOT NULL, [Name]
So I have a table like this: create table `test` ( `testId` int(11) not
I have a table that's created like this: CREATE TABLE bin_test (id INTEGER PRIMARY
This is my table: CREATE TABLE [Test].[dbo].[MyTest] ( [Id] BIGINT NOT NULL, [FId] BIGINT
I have a test table like this CREATE TABLE #temp ( rid INT IDENTITY

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.