Re: postgresql_fdw doesn't handle defaults correctly - Mailing list pgsql-hackers

From Amit Langote
Subject Re: postgresql_fdw doesn't handle defaults correctly
Date
Msg-id 56161f6d-510a-0181-fbf6-6b74fd4d833d@lab.ntt.co.jp
Whole thread Raw
In response to Re: postgresql_fdw doesn't handle defaults correctly  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: postgresql_fdw doesn't handle defaults correctly
List pgsql-hackers
On 2018/06/27 15:33, Pavel Stehule wrote:
>>> Unfortunately, when I use identity column
>>>
>>> create table foo(a int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, b
>> date
>>> default current_date, c int);
>>>
>>> then import doesn't fail, but still it doesn't work
>>
>> It seems that, unlike DEFAULT, the information about IDENTITY is not
>> stored in pg_attrdef catalog.  It's rather stored in
>> pg_attribute.attidentity.  Looking at postgres_fdw's IMPORT FOREIGN SCHEMA
>> implementation, while it fetches the DEFAULT expression from pg_attrdef
>> when asked, it seems that it does not fetch the value of attidentity.
>>
>> Not sure if we should consider that a bug or simply an unsupported case
>> like a DEFAULT referring to a sequence.  In any case, if it's an
>> unsupported case, we should perhaps error out in a more user-friendly
>> manner.
>>
> 
> I don't understand, why is necessary to replace missing values by NULLs?
> 
> I didn't expect so insert into foo(c) values(10)
> 
> will be translated to
> 
> insert into foo(a,b,c) values(NULL, NULL, 10)

That's what we do if there is no default value to fill in if the INSERT
command didn't specify the value.  In this case, even if the table on the
remote side may be define with column as IDENTITY, the IMPORT FOREIGN
SCHEMA command does not fetch that information and creates the foreign
table locally without any default value.  So, that's a missing piece of
functionality in postgres_fdw's implementation of the command.

As a workaround for that missing functionality, one can always create the
foreign table by hand and specify DEFAULT and IDENTITY explicitly as
necessary.

Thanks,
Amit



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Constraint documentation
Next
From: Andres Freund
Date:
Subject: Re: Portability concerns over pq_sendbyte?