Re: FOREIGN TABLE and IDENTITY columns

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, Julien Rouhaud <rjuju123(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: FOREIGN TABLE and IDENTITY columns
Date: 2024-10-15 13:16:40
Message-ID: dff10825-4c61-4967-8a67-bbf3c22824d3@eisentraut.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 08.10.24 18:40, Ashutosh Bapat wrote:
> On Tue, Oct 8, 2024 at 7:57 PM Julien Rouhaud <rjuju123(at)gmail(dot)com> wrote:
>> I was looking at the CREATE FOREIGN TABLE documentation to see if IDENTITY
>> columns were supported, and according to the doc they're not: only GENERATED
>> ALWAYS AS ( expr ) STORED is supported.
>>
>> However, a quick test shows that this is supported (same as serial datatype),
>> and apparently behaves as expected. Looking at the grammar, CreateStmt and
>> CreateForeignTableStmt actually share the same rule for the column definitions
>> (OptTableElementList) so the behavior seems expected. The parse analysis code
>> is also mostly shared between the two, with only a few stuff explicitly
>> forbidden for foreign tables (primary keys and such).
>>
>> It looks like this is just an oversight in the documentation? If so, it seems
>> like the CREATE and ALTER FOREIGN TABLE pages needs to be updated. The ALTER
>> FOREIGN TABLE page is also at least lacking the SET / DROP EXPRESSION clauses.
>
> The rows inserted/udpated on the foreign server won't honour the local
> IDENTITY constraint. Maybe that's why we don't want to support
> identity column in foreign tables.

Stored generated columns have a similar issue: The column is computed on
the local server and the remote server must store it and return it. If
you go and update it manually on the remote server, you break this.

I think this still has use, though, depending on how you use foreign
tables. If you use foreign tables as a frontend to data that is
actually managed on the remote side, then generated columns and identity
columns don't make much sense. But if you plan to manage the data
through the foreign table, and the remote side is just dumb storage
(like for sharding), then generated columns and identity columns could
be useful.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2024-10-15 13:22:53 Re: Set query_id for query contained in utility statement
Previous Message Artur Zakirov 2024-10-15 13:16:07 Re: type cache cleanup improvements