pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: George Moga <george@dsn.ro>
To: salva@ronincoders.com
To: pgsql-sql@postgresql.org
Subject: Re: dates in functions
Date: Mon, 05 Mar 2001 18:13:25 +0200
Message-ID: <3AA3BB25.28A68D8E@dsn.ro> (raw)
References: <3A9FB338.A5A174C9@yahoo.com>

Salvador Mainé wrote:

> Hello:
>
> I'm trying to define a function that, given a date, returns its month.
> The definition is as follows:
>
> CREATE function anyo_hidro (date) returns int AS '
>        BEGIN
>        RETURN date_part("month",$1);
>        END;
> ' LANGUAGE 'plpgsql';
>
> But when I do:
>
> select anyo_hidro('1-1-1999');
>
> I get the following error:
>
> ERROR:  Attribute 'month' not found

Try,

test=# CREATE function anyo_hidro (date) returns int AS '
       BEGIN
                  RETURN date_part(\'month\',$1::datetime);
       END;
' LANGUAGE 'plpgsql';

CREATE
test=#  select anyo_hidro('1-1-1999');
 anyo_hidro
------------
          1
(1 row)


I use:

test=# select version();
                            version
---------------------------------------------------------------
 PostgreSQL 7.0.3 on i686-pc-linux-gnu, compiled by gcc 2.95.3
(1 row)

test=#


George Moga,
    Data Systems Srl





view thread (3+ messages)

Message-ID: <3AA3BB25.28A68D8E@dsn.ro>
Permalink:  ../3AA3BB25.28A68D8E@dsn.ro/
Also on:    postgresql.org/message-id/3AA3BB25.28A68D8E@dsn.ro

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: george@dsn.ro, salva@ronincoders.com
  Subject: Re: dates in functions
  In-Reply-To: <3AA3BB25.28A68D8E@dsn.ro>
  References: <3A9FB338.A5A174C9@yahoo.com> <3AA3BB25.28A68D8E@dsn.ro>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox