Re: postgresql_fdw doesn't handle defaults correctly

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: postgresql_fdw doesn't handle defaults correctly
Date: 2018-06-27 06:59:44
Message-ID: CAFj8pRCSFiPsWFGmxTLB6mqD4qsBHAqQO9_OxOy1yFkd3U0rBQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2018-06-27 8:45 GMT+02:00 Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>:

> 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.
>

It is works but I afraid so this design is pretty unhappy.

It created implicit local sequence .. for remote object. Maybe I use strong
worlds, but is not good design. In this case, when identity column is
defined, then driver should not to generate this value.

creating any local object for remote object should not to work - it is like
indexes or some else. I don't understand to motivation for this design.

Regards

Pavel

> Thanks,
> Amit
>
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2018-06-27 07:30:04 Re: postgresql_fdw doesn't handle defaults correctly
Previous Message Amit Langote 2018-06-27 06:58:20 Re: [HACKERS] advanced partition matching algorithm for partition-wise join