Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y0CQy-0006HU-RE for pgsql-sql@arkaria.postgresql.org; Sun, 14 Dec 2014 16:54:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y0CQx-0007Nc-Mj for pgsql-sql@arkaria.postgresql.org; Sun, 14 Dec 2014 16:54:15 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Y0CQw-0007NR-S3 for pgsql-sql@postgresql.org; Sun, 14 Dec 2014 16:54:15 +0000 Received: from mail-qa0-x22a.google.com ([2607:f8b0:400d:c00::22a]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Y0CQp-0003b6-FH for pgsql-sql@postgresql.org; Sun, 14 Dec 2014 16:54:13 +0000 Received: by mail-qa0-f42.google.com with SMTP id n4so784985qaq.15 for ; Sun, 14 Dec 2014 08:54:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=q1JH+rfD9UJj1rL7pATm21N9BYeCr9l8hDzcoVffrBA=; b=zbV+v696RN/b5b3fARKdw/l3N7+Hs4m/JxumqyXC2aGz7/mjzsZQsBx5d+vqP8jY9j B5+/NzccNwrOKRduREup2RwNt+nRNtSUphgOfSYke79tYmWYN2lze+HjCgfUX+Sg9qLC k+7Rt7twZ+kvPReTe/US1Ks8XybsYW7D+e58T9w+JMDl4mFNc3zBFlVJE4c4xnDuIngx 56nmxgDi7JIV9kppOiFb9O3+yCPGvMQsnFAyb5PlwIOsZHCHrGLhFYP39YmxTUeNpJB+ o6i5T8322MjeOoV0myEfWRNCVQtefHK+tKweBK+pS2zESAluJJB4TJMqz8LfwPgJZod1 U75A== X-Received: by 10.140.43.195 with SMTP id e61mr33265666qga.13.1418576046308; Sun, 14 Dec 2014 08:54:06 -0800 (PST) Received: from ?IPv6:2606:a000:a180:a100:d250:99ff:fe38:d0da? ([2606:a000:a180:a100:d250:99ff:fe38:d0da]) by mx.google.com with ESMTPSA id t2sm4319303qae.6.2014.12.14.08.54.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Dec 2014 08:54:05 -0800 (PST) Message-ID: <548DBFB3.1090304@gmail.com> Date: Sun, 14 Dec 2014 11:49:55 -0500 From: Ed Rahn User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.3.0 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: foregin table insert error References: <548D54C9.3040005@gmail.com> <548D9F19.9080405@aklaver.com> In-Reply-To: <548D9F19.9080405@aklaver.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On 12/14/2014 09:30 AM, Adrian Klaver wrote: > On 12/14/2014 01:13 AM, Ed Rahn wrote: >> Hi, >> I have a foreign table that I'm getting an insert error on: >> >> horsedata=# insert into remote_cache (entry_id, name_id) values(2,1); >> ERROR: null value in column "id" violates not-null constraint >> DETAIL: Failing row contains (null, 1, 2, null). >> CONTEXT: Remote SQL command: INSERT INTO public.cache(id, name_id, >> entry_id, value) VALUES ($1, $2, $3, $4) >> >> >> Here is the remote table client side: >> horsedata=# \d remote_cache >> Foreign table "public.remote_cache" >> Column | Type | Modifiers | FDW Options >> ----------+---------+-----------+------------- >> id | integer | | >> name_id | integer | | >> entry_id | integer | | >> value | integer | | >> Server: home >> FDW Options: (table_name 'cache') >> >> >> And here's cache server side: >> horsedata=# \d cache; >> Table "public.cache" >> Column | Type | Modifiers >> ----------+------------------+---------------------------------------------------- >> >> >> id | integer | not null default >> nextval('cache_id_seq'::regclass) >> name_id | integer | >> entry_id | integer | >> value | double precision | >> Indexes: >> "cache_pkey" PRIMARY KEY, btree (id) >> "cache_name_id_entry_id_key" UNIQUE CONSTRAINT, btree (name_id, >> entry_id) >> "ix_cache_entry_id" btree (entry_id) >> "ix_cache_name_id" btree (name_id) >> >> >> Any suggestions? > > Yes, see here: > > http://www.postgresql.org/message-id/CA+mi_8bfkaFPNPPx6_W_T_0J9OEMSfXQKCDZo=OMJpWWcCKtoA@mail.gmail.com > > I tried something similar using -1 as well as the above: On server I set: create function inc_id_cache() returns trigger as $inc$ begin if NEW.id = NULL then NEW.id := nextval('cache_id_seq'); end if; return NEW; end; $inc$ language plpgsql; create trigger inc before insert on cache for each row execute procedure inc_id_cache(); Now in both cases I get: horsedata=# insert into remote_cache(name_id, entry_id) values (1, 8); ERROR: null value in column "id" violates not-null constraint DETAIL: Failing row contains (null, 1, 8, null). CONTEXT: Remote SQL command: INSERT INTO public.cache(id, name_id, entry_id, value) VALUES ($1, $2, $3, $4) thanks Ed -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql