Received: from sss2.sss.pgh.pa.us (sss.pgh.pa.us [209.114.166.2]) by hub.org (8.9.3/8.9.3) with ESMTP id LAA64868 for ; Tue, 11 Apr 2000 11:29:38 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss2.sss.pgh.pa.us (8.9.3/8.9.3) with ESMTP id LAA01027; Tue, 11 Apr 2000 11:29:31 -0400 (EDT) To: PDH.KFI3@t-online.de (Andreas Stahlhut) cc: pgsql-sql@postgresql.org Subject: Re: function date_part In-reply-to: <00041115394501.03152@boerse> References: <00041115394501.03152@boerse> Comments: In-reply-to PDH.KFI3@t-online.de (Andreas Stahlhut) message dated "Tue, 11 Apr 2000 15:07:15 +0200" Date: Tue, 11 Apr 2000 11:29:31 -0400 Message-ID: <1024.955466971@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200004/107 PDH.KFI3@t-online.de (Andreas Stahlhut) writes: > If I use this in a create table like > create table primtab( > primkey > int4 > primary key > default > int4(date_part('year', 'now'::datetime) * 1000+nextval('serial_seq')) > ); > it never works. > ERROR: parser: parse error at or near "'" The default-value support in 6.5.* is pretty limited, not to say broken; I think it is probably failing on the '::datetime' part of that expression. 7.0 copes just fine. As a workaround for 6.5, you might try writing date_part('year', now()) instead. > If I use it in a create function like > create function primfnc() returns int4 > as 'select .... as primnum' > language 'sql'; > it never works. > ERROR: parser: parse error at or near "year" This is probably pilot error. Did you remember to double the ' symbols in the body of the function definition? Remember the body is itself a single-quoted string, so any embedded quote marks must be written '' (or \' if you prefer). regards, tom lane