Re: Column defaults for foreign tables (was Re: [v9.3] writable foreign tables)

From: Thom Brown <thom(at)linux(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>, "pgsql-hackers(at)postgreSQL(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Column defaults for foreign tables (was Re: [v9.3] writable foreign tables)
Date: 2013-03-13 20:13:53
Message-ID: CAA-aLv5m-rvTJTWtF66n5qKnjn8t_9D_nVBGFL4H7CS1mHHQ-w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 13 March 2013 19:04, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at> writes:
>>> Yeah, I'm drifting towards the position that we should just define the
>>> defaults as being whatever they are locally, rather than trying to be
>>> cute about supporting remotely-executed defaults.
>
>> That was my first thought on the topic, to have a solution that
>> is simple (if not perfect).
>> Your argument that it would be unpleasant to lose the ability
>> to use sequence-generated remote default values made me reconsider.
>
>> But there is a workaround, namely to use a trigger before insert
>> to generate an automatic primary key (e.g. if the inserted value is
>> NULL).
>
> Another attack is to set up a different foreign table pointing to the
> same remote table, but lacking the sequence column. When you insert via
> that table, you'll get the remote's default for the hidden column.
> This doesn't require any weird triggers on the remote side, but it could
> be hard to persuade existing apps to use the second foreign table.

How about:

CREATE FOREIGN TABLE tablename (id int DEFAULT PASSTHROUGH) SERVER pg_server;

That way it will pass DEFAULT through to the remote table as it's
defined on the table. Users can then explicitly insert values, or
select the default, which will configured to ensure the default on the
remote server is used... although I suspect I'm overlooking something
here.

--
Thom

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Boszormenyi Zoltan 2013-03-13 20:28:34 Re: Re: Proposal for Allow postgresql.conf values to be changed via SQL [review]
Previous Message Joe Conway 2013-03-13 20:12:21 Re: pg_dump selectively ignores extension configuration tables