Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gu2Jj-0002rb-1b for pgsql-general@arkaria.postgresql.org; Wed, 13 Feb 2019 21:43:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gu2Jg-0003v0-1X for pgsql-general@arkaria.postgresql.org; Wed, 13 Feb 2019 21:43:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gu2Jf-0003ut-Pq for pgsql-general@lists.postgresql.org; Wed, 13 Feb 2019 21:43:39 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gu2Jc-0005my-2L for pgsql-general@postgresql.org; Wed, 13 Feb 2019 21:43:39 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id B798F23D2A; Wed, 13 Feb 2019 16:43:33 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 13 Feb 2019 16:43:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=8 XN6oAFSxN1Ij4JXfG1P9Q+1IcgcBfLtbC8NOdOiFfA=; b=Z11QzqkL6KibNLdMh jHud8FRwohoi0UCrmvVEuhWD9TM7xoTWWSW9mr/AvpeiKyKcVq5kraHoFyQdeuyj b708y4WY1o84RR+s8GDLqZ4szVgltGBrYw2knJM0NVIUVt7jW/eRbP+hSe1dUvIC Cr91Wh4XvvkKfHV2/Yqujfe4ncTFr9T6wtRGqBWphnPltjU80ZiGH/OZOOveJWqG kbshtIWxOhNlYgD3P0qgC8IVdSfbpxbrlNG/ScTtbBSsASFZkMSF38zm2a4Ot06N 3sV2IGo/6TJs3aVPQ7d0zlfWvphTGd35JUqNAoR11W3B8xXAE+6d8oz18hVdq6aB dyRag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=8XN6oAFSxN1Ij4JXfG1P9Q+1IcgcBfLtbC8NOdOiF fA=; b=x9sk6XOAV+iGBsnRphaXKqWrbfeAklF9Ks/5Snhf8hBTR4Y0XUewTU80T c7fUHoZzp5yHTDMtOq9LdovA/UA+/kbtP/kETlPiOwAGcS8XFMpG1iIt0gVQGkeL shuDaX3pEe1LUnM0ubIVoG9v0QdmTNuuAlUi+mZbtamEKqra07r124s9GGH66Bcu DhZ62e8CkhABSBmGpNjj//QzYIv2TybU9VK8BTNWMh+Rh9lk1niY5h+jG6FDFYx6 BUpIVewLPkx3dniD4rN0z4Rnbu5yfEnGl6BIkPXY2CV+KBPGHNQBigaNjp7Ptb6b P0QhukiUE8E7zk97bPpwduKeoYZ6A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledruddtfedgudehfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthenuceurghilhhouhhtmecu fedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepuffvfhfhkf fffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcu oegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucffohhmrghinh epphhoshhtghhrvghsthdrohhrghdptgdrihgupdgtrdhnrghmvgenucfkphepjedurddv uddvrdduhedtrddvtddvnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkh hlrghvvghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.4] (unknown [71.212.150.202]) by mail.messagingengine.com (Postfix) with ESMTPA id 877361030F; Wed, 13 Feb 2019 16:43:32 -0500 (EST) Subject: Re: Postgrest over foreign data wrapper To: Michael Lewis , adrien ruffie Cc: "pgsql-general@postgresql.org" References: From: Adrian Klaver Message-ID: Date: Wed, 13 Feb 2019 13:43:31 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2/13/19 1:36 PM, Michael Lewis wrote: > You don't need an fkey to write a select statement with a join. I think > I must be missing something. Are you wanting it to enforce integrity Me to until I looked at this: http://postgrest.org/en/v5.2/api.html#resource-embedding "PostgREST can also detect relations going through join tables. Thus you can request the Actors for Films (which in this case finds the information through Roles). You can also reverse the direction of inclusion, asking for all Directors with each including the list of their Films: GET /directors?select=films(title,year) HTTP/1.1 Important Whenever foreign key relations change in the database schema you must refresh PostgREST’s schema cache to allow resource embedding to work properly. See the section Schema Reloading. " > across the dblink? Or are you adding an fkey with the assumption that > you will get an index? > * > * > * > * > *Michael Lewis  | Software Engineer* > *Entrata** > * > *c:**619.370.8697 * > > > On Wed, Feb 13, 2019 at 2:04 PM adrien ruffie > wrote: > > we have a tricky problem with my colleague. > We have to database db1 and db2 linked by a foreign data wrapper > connection. > 1 table "contractline" in db1 and "contract" in db2. > > We use postgrest in order to request db2 via CURL. > But we want to add a link between previous tables. > > In db2 we have a foreign table ft_contractline > example: > >     Column    |           Type           | Collation | Nullable > | Default | FDW options | Storage  | Stats target | Description > --------------+--------------------------+-----------+----------+---------+-------------+----------+--------------+------------- >  id           | character varying(1024)  |           | not null > |         |             | extended |              | >  ccode      | text                     |           |          | >         |             | extended |              | >  status       | text                     |           | >  |         |             | extended |              | > > We want to add for example, the following constraint: > ALTER TABLE contract ADD CONSTRAINT > contractline_ft_contract_fkey FOREIGN KEY (contractid) > REFERENCES ft_contractline(ccode); > > in order to use the following query (via CURL on db2): > SELECT c.name , c.id FROM contract > c JOIN ft_contractline ft_c ON c.id = ft_c.ccode > WHERE c.type = 'business' > > but we saw, isn't possible to add a foreign key on 'contract' > table of db2 to 'ft_contractline' foreign table ... > > Do you know way to do it ? > > Thank all and best regards. > > Adrien > -- Adrian Klaver adrian.klaver@aklaver.com