Received: from www-uk-05.digiserve.com ([195.97.231.11]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f2DD4Mx14861 for ; Tue, 13 Mar 2001 08:04:22 -0500 (EST) (envelope-from dev@archonet.com) Received: from mainbox.archonet.com (mwynhau.demon.co.uk [193.237.186.96]) by www-uk-05.digiserve.com (8.9.1/8.9.1) with ESMTP id NAA28710; Tue, 13 Mar 2001 13:05:12 GMT Received: from client (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with SMTP id 23FB82A681; Tue, 13 Mar 2001 12:38:52 +0000 (GMT) Message-ID: <004001c0abba$8e8dd360$1001a8c0@archonet.com> From: "Richard Huxton" To: "Christopher Sawtell" , References: <01031400530600.00996@berty> Subject: Re: my pgsql error? Date: Tue, 13 Mar 2001 12:38:22 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Archive-Number: 200103/252 X-Sequence-Number: 1911 From: "Christopher Sawtell" > Please could a kind soul help me with this. > I can't find _any_ - however cryptic - docs about plpgsql. You need to look in the User's guide Chapter 9 (in the pre-release docs anyway) > create function nice_date(date) returns varchar as ' > declare > t alias for $1; > d text; > m text; > y text; > begin > day := rtrim(to_char(\'t\'::timestamp, \'Day\')); > month := rtrim(to_char(\'t\'::timestamp, \'DD Month\')); > year := rtrim(to_char(\'t\'::timestamp, \'YYYY\' )); > nd := d || m || y; > end; > return nd; > end;' language 'plpgsql'; Two "end;" lines - remove the first to fix the error you are getting. Also - you define d,m,y and use day,month,year You don't define nd The to_char lines you are using will try and convert the literal string 't' to a timestamp. You will want some spaces in the nd value. So, your script will become: create function nice_date(date) returns varchar as ' declare t alias for $1; d text; m text; y text; nd text; begin d := rtrim(to_char(t::timestamp, \'Day\')); m := rtrim(to_char(t::timestamp, \'DD Month\')); y := rtrim(to_char(t::timestamp, \'YYYY\' )); nd := d || \' \' || m || \' \' || y; return nd; end;' language 'plpgsql'; Note to readers: this is not a general service, I'm in a good mood ;-) For a moment I thought you could do to_char(now(),'Day DD Month YYYY' but you're quite right you need to rtrim() the various pieces. - Richard Huxton