Re: my pgsql error? - Mailing list pgsql-sql

From Richard Huxton
Subject Re: my pgsql error?
Date
Msg-id 004001c0abba$8e8dd360$1001a8c0@archonet.com
Whole thread Raw
In response to my pgsql error?  (Christopher Sawtell <csawtell@xtra.co.nz>)
Responses Re: my pgsql error?  (Christopher Sawtell <csawtell@xtra.co.nz>)
List pgsql-sql
From: "Christopher Sawtell" <csawtell@xtra.co.nz>

> 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 '
declaret 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



pgsql-sql by date:

Previous
From: juerg.rietmann@pup.ch
Date:
Subject: copy a record from one table to another (archive)
Next
From: Christof Glaser
Date:
Subject: Re: my pgsql error?