Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id B9AE35F38E8 for ; Tue, 8 Nov 2011 17:46:08 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 26507-03 for ; Tue, 8 Nov 2011 21:46:02 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from smtp105.prem.mail.ac4.yahoo.com (smtp105.prem.mail.ac4.yahoo.com [76.13.13.44]) by mail.postgresql.org (Postfix) with SMTP id 2AECF5F38E6 for ; Tue, 8 Nov 2011 17:46:02 -0400 (AST) Received: (qmail 74069 invoked from network); 8 Nov 2011 21:46:00 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=rehqLc0j7hM+bciOrcPkzCaTJlBnTbHfeRqQLjfSflqObR4nBuZKpV5rK4540J6XHoOkGVvH3C/QqXMB1pAQ1eGOBBa3cBIfCs/gtmGijnjE1/pWf4KAmD01/X7LVgVwnXkJkl8w7lX36Wgf7zXzRFaLvfro3lRgnYcOddXWb7Y= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1320788760; bh=zGzzFanp+3Oq4nTwtlfr6SszbiWblPjol4Iqs08te0I=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=w4hgTL+tp5R3lp8X0MOx9hNbpwDwDmEMBO/xHgY+utu7Cu9HgUXATwGsvp4hRIA13rW+z5g4rtGGL+y+s0GbRLtl2gfLXYmCy2jMGh6enbTDwfDFihT0eZnXhk0izmCtDLW4MwkGzqfmgqHi4wAhUrxEk4CvRSvIlfHgJIWnd0E= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: EG5x0ZwVM1kyFyaRSnD6XhOdT3gwl8dj439RkQVi2z8WPFq LtqdNGENh34RjiPBfWQvAuQYYu1DK23bGLzkkYCNMZpqtvQlRbAuoYZu09R7 NCZXDCRjoV.wK0uE_rf_GZLjqTGV6av2xLsQITU4swIzFmSRPqKOKAs5ITRx nhn1fA1TX1ofFDEhvf1wWpyZf0dXaY2YtcqbsNpQrtrvcvsBz94X12feHKIk .vBp1NKdB9oQ9ccRAG1e7nk_HUEInnTEY8Hx9pdfb7wOHFgAP5gJNunA1IKk vaSQXFgkZbOk6unhMNvKrsOEqPuZClM5EZjJt_Ujj8._45JZAgSRZcyz1aO7 ulYsrZzqJMghrRtwKqVpAkG0c.rFu1qklDsWPz2Bu7_1iOqGHjsytA5aA.to JUQ4hOg-- X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from WolfDog (polobo@24.93.23.188 with login) by smtp105.prem.mail.ac4.yahoo.com with SMTP; 08 Nov 2011 13:46:00 -0800 PST From: "David Johnston" To: "'Russell Keane'" , References: <8D0E5D045E36124A8F1DDDB463D548557CC7AB3B52@mxsvr1.is.inps.co.uk> In-Reply-To: <8D0E5D045E36124A8F1DDDB463D548557CC7AB3B52@mxsvr1.is.inps.co.uk> Subject: Re: Updatable view should truncate table fields Date: Tue, 8 Nov 2011 16:45:59 -0500 Message-ID: <007a01cc9e5f$cddf0a90$699d1fb0$@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQIV9TctJ1AYrdO0L9L+ds/VztMC6ZUQ01/A Content-Language: en-us X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-3.099 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RP_MATCHES_RCVD=-1.201, UNPARSEABLE_RELAY=0.001 X-Spam-Level: X-Archive-Number: 201111/39 X-Sequence-Number: 36012 From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Russell Keane Sent: Tuesday, November 08, 2011 4:34 PM To: pgsql-sql@postgresql.org Subject: [SQL] Updatable view should truncate table fields Using PostgreSQL 9.0. We have a table which is not accessible by client code. We also have views with rules and triggers to intercept any insert or update statements and write that data in a slightly different format back to the table. A particular field in the table is currently 5 chars but recently we have had update / insert statements containing more than 5. This obviously (and correctly) throws an error. We can extend the table to accept more than 5 characters but the view must return 5 characters. If we try to extend the table to accept, say, 10 characters the view will display 10. If I also cast the view field to 5 characters then any insert with more than 5 characters still fails. ----------------------------------------------------- Haven't used updatable VIEWs yet but couldn't you either define the VIEW as: CREATE VIEW .... AS ( SELECT field1, field2::varchar(5) AS field2 FROM table ); Or, alternatively, define the INSERT/UPDATE functions to perform the truncation upon inserting into the table? Does the INSERT itself throw the error or is one of your functions raising the error when it goes to insert the supplied value into the table? It is generally bad form to modify user data for storage so either you truly have a length limitation that you need to restrict upon data entry (in which case everything is working as expected) or you should allow any length of data to be input and, in cases where the output medium has length restrictions, you can ad-hoc limit the display length of whatever data was provided. David J.