Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1US8g9-0001iS-PL for pgsql-sql@arkaria.postgresql.org; Tue, 16 Apr 2013 16:24:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1US8g8-0007se-SZ for pgsql-sql@arkaria.postgresql.org; Tue, 16 Apr 2013 16:24:20 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1US8g7-0007sN-Qq for pgsql-sql@postgresql.org; Tue, 16 Apr 2013 16:24:19 +0000 Received: from plane.gmane.org ([80.91.229.3]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1US8g4-0003l7-S3 for pgsql-sql@postgresql.org; Tue, 16 Apr 2013 16:24:19 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1US8g0-0004F7-Ap for pgsql-sql@postgresql.org; Tue, 16 Apr 2013 18:24:12 +0200 Received: from frigga.summersault.com ([12.161.105.138]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 16 Apr 2013 18:24:12 +0200 Received: from mark by frigga.summersault.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 16 Apr 2013 18:24:12 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Mark Stosberg Subject: Peer-review requested of soft-delete scheme Date: Tue, 16 Apr 2013 12:24:00 -0400 Lines: 39 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: frigga.summersault.com User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 X-Enigmail-Version: 1.5.1 X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Hello, I'm working on designing a soft-delete scheme for our key entity-- there are 17 other tables that reference our key table via RI. Let's call the table "foo". I understand there are a couple common design patterns for soft-deletes: 1. Use a trigger to move the rows to a "tombstone table". 2. Add an "deleted flag" to the table. The "tombstone table" approach is out for us because all the RI. The "deleted flag" approach would be a natural fit for us. There's already a "state" column in the table, and there will only be a small number rows in the "soft-deleted" state at a time, as we'll hard-delete them after a few months. The table has only about about 10,000 rows in it anyway. My challenge is that I want to make very hard or impossible to access the soft-deleted rows through SELECT statements. There are lots of selects statements in the system. My current idea is to rename the "foo" table to something that would stand-out like "foo_with_deleted_rows". Then we would create a view named "foo" that would select all the rows except the soft-deleted views. I think that would make it unlikely for a developer or reviewer to mess up SELECTs involving the statement. Inserts/Updates/Delete statements against the table are view, and coud reference the underlying table directly. Is this sensible? Is there another approach to soft-deletes I should be considering? Thanks! Mark -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql