Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id A58D6116A13A for ; Tue, 21 Feb 2012 16:51:54 -0400 (AST) Received: from mgate.mtholyoke.edu ([138.110.1.180] helo=depot.mtholyoke.edu) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Rzwgg-0003xR-9S for pgsql-sql@postgresql.org; Tue, 21 Feb 2012 20:51:53 +0000 Received: from smtp.mtholyoke.edu (smtp.mtholyoke.edu [138.110.1.184]) by depot.mtholyoke.edu (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id q1LKpUoq000940 for ; Tue, 21 Feb 2012 15:51:30 -0500 Received: from rock.mtholyoke.edu (rock.mtholyoke.edu [138.110.86.70]) by smtp.mtholyoke.edu (Postfix) with ESMTPS id 93467BFA02 for ; Tue, 21 Feb 2012 15:51:30 -0500 (EST) Received: from rock.mtholyoke.edu (rpeterso@localhost [127.0.0.1]) by rock.mtholyoke.edu (8.14.3/8.14.3/Debian-9.4) with ESMTP id q1LKpUQV016565 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Tue, 21 Feb 2012 15:51:30 -0500 Received: (from rpeterso@localhost) by rock.mtholyoke.edu (8.14.3/8.14.3/Submit) id q1LKpUvs016555 for pgsql-sql@postgresql.org; Tue, 21 Feb 2012 15:51:30 -0500 Date: Tue, 21 Feb 2012 15:51:30 -0500 From: Ron Peterson To: pgsql-sql@postgresql.org Subject: on insert rule with default value Message-ID: <20120221205130.GG29194@mtholyoke.edu> Mail-Followup-To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Organization: Mount Holyoke College X-Operating-System: Debian GNU/Linux User-Agent: Mutt/1.5.20 (2009-06-14) X-Spam-Score: -2.6 () RP_MATCHES_RCVD X-Scanned-By: MIMEDefang 2.67 on 138.110.1.180 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/65 X-Sequence-Number: 36358 My rule below does not insert the the same uuid value into the test_log table as is created in the test table when I insert a new value. I know I've worked through this before, but I'm not remembering why this is. What's a right way to do this? create table test ( anid uuid not null default encode( gen_random_bytes( 16 ), 'hex' )::uuid primary key, value text ); create table test_log ( anid uuid, value text, op text, attime timestamp with time zone ); create rule test_rule_a as on insert to test do ( insert into test_log ( anid, value, op, attime ) values ( new.anid, new.value, 'insert', now() ) ); -- Ron Peterson Network & Systems Administrator Mount Holyoke College http://www.mtholyoke.edu/~rpeterso