Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b7SRE-0007v7-Q4 for pgsql-bugs@arkaria.postgresql.org; Mon, 30 May 2016 19:01:20 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b7SRE-0006l6-D5 for pgsql-bugs@arkaria.postgresql.org; Mon, 30 May 2016 19:01:20 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b7SRD-0006kz-Vj for pgsql-bugs@postgresql.org; Mon, 30 May 2016 19:01:20 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b7SRA-000634-Ja for pgsql-bugs@postgresql.org; Mon, 30 May 2016 19:01:19 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u4UJ1EPr021417; Mon, 30 May 2016 15:01:14 -0400 From: Tom Lane To: "David G. Johnston" cc: kes-kes@yandex.ru, "pgsql-bugs@postgresql.org" Subject: Re: BUG #14164: Postgres allow to insert more data into field than this field allow In-reply-to: References: <20160530085041.19432.93208@wrigleys.postgresql.org> <13914.1464628209@sss.pgh.pa.us> Comments: In-reply-to "David G. Johnston" message dated "Mon, 30 May 2016 14:02:19 -0400" Date: Mon, 30 May 2016 15:01:14 -0400 Message-ID: <21416.1464634874@sss.pgh.pa.us> X-Pg-Spam-Score: -3.3 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org "David G. Johnston" writes: > On Mon, May 30, 2016 at 1:10 PM, Tom Lane wrote: >> I would say this is a bug in mysql_fdw, not Postgres proper. In general >> it's the responsibility of an FDW to ensure that data it passes back >> meets the constraints of the foreign table declaration. > At some point in this SELECT->INSERT process there has to be a recognition > that the data we are seeing is external and needs to be validated against > the rules and assumptions of PostgreSQL. It's not our fault that mysql_fdw > is broken but it is our fault that we allowed its brokenness to result is > non-conforming persisted data. > Either the SELECT should fail because a PostgreSQL varchar(255) cannot hold > longer data (probably this) or the INSERT should fail so that at least the > impact of the broken varchar is limited to an active query and doesn't make > it onto disk. Indeed, the SELECT should have failed, and it's mysql_fdw that should have issued the error. We cannot expect to protect users against every sort of malfeasance or misfeasance that might occur in extension C code. Consider for example that the Datum mysql_fdw is handing back and claiming to be varchar(255) might not be textual at all, or it might be in the wrong encoding, etc etc. It wouldn't even be possible for the core code to detect some of those cases, and it certainly would impose a lot of overhead to add checking that should be redundant. (BTW, I checked this and verified that an equivalent case in postgres_fdw does throw an error; so it's *possible* for an FDW to get this right. mysql_fdw simply doesn't.) regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs