Received: from fw.mccons.net (adsl-65-64-105-41.dsl.kscymo.swbell.net [65.64.105.41]) by postgresql.org (Postfix) with ESMTP id BD797476ACA for ; Fri, 12 Apr 2002 03:21:24 -0400 (EDT) Received: (from root@localhost) by fw.mccons.net (8.11.3/8.11.4) id g3C7LF020690 for pgsql-admin@postgresql.org; Fri, 12 Apr 2002 02:21:15 -0500 (CDT) (envelope-from bmccane@mccons.net) Received: from localhost (localhost [127.0.0.1]) by fw.mccons.net (8.11.3/8.11.4av) with ESMTP id g3C7L7j20681 for ; Fri, 12 Apr 2002 02:21:07 -0500 (CDT) (envelope-from bmccane@mccons.net) Date: Fri, 12 Apr 2002 02:21:07 -0500 (CDT) From: Brian McCane To: pgsql-admin Subject: Re: ALTER TABLE ... SET DEFAULT In-Reply-To: <20020412015602.S18686-100000@fw.mccons.net> Message-ID: <20020412021729.Y20593-100000@fw.mccons.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS perl-11 X-Razor-Spam-ID: 84020cb46c3cbc8990adda3267db0b89f9878198 X-Archive-Number: 200204/97 X-Sequence-Number: 3985 Okay, I can't wait until morning for an answer, so I made one up ;-). I already have a function on this particular table which does processing 'BEFORE INSERT'. As a temporary hack (or maybe permanent depending on anyones response), I have added code to see if 'updated' IS NULL and setting it to the return value of 'since_epoch()' if it is. I suspect that since I am already calling this function, it might actually be faster than adding the 'set default' to the table anyway, especially since the function 'iscacheable' and is being used in a transaction block. -brian On Fri, 12 Apr 2002, Brian McCane wrote: > > > > I have a field called 'updated' of type 'integer' in a table. I have > created a function called 'since_epoch' which is declared with iscacheable > and returns the value of 'extract(epoch from now())'. I want to make > 'updated' have a default of 'since_epoch()'. I cannot get it to work with > the following command: > > alter table foo alter column updated set default 'since_epoch()' ; > > this gets the error: > > ERROR: pg_atoi: error in "since_epoch()": can't parse "since_epoch()" > > I tried using 'since_epoch()::integer', but that failed as well. > Is it possible to make the default value of an integer field use a > function similar to how we use 'now()' for date and timestamp fields? > > - brian > > Wm. Brian McCane | Life is full of doors that won't open > Search http://recall.maxbaud.net/ | when you knock, equally spaced amid those > Usenet http://freenews.maxbaud.net/ | that open when you don't want them to. > Auction http://www.sellit-here.com/ | - Roger Zelazny "Blood of Amber" > > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org >