pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feeddates in functions
3+ messages / 2 participants
[nested] [flat]
* dates in functions
@ 2001-03-02 14:50 Salvador Mainé <salvamaine@yahoo.com>
2001-03-02 14:57 ` Re: dates in functions Salvador Mainé <salvamaine@yahoo.com>
2001-03-05 16:13 ` Re: dates in functions George Moga <george@dsn.ro>
0 siblings, 2 replies; 3+ messages in thread
From: Salvador Mainé @ 2001-03-02 14:50 UTC (permalink / raw)
To: pgsql-sql
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
Why doesn't date_part work with pl/sql functions?
Thanks
--
Salvador Maine
http://www.ronincoders.com
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: dates in functions
2001-03-02 14:50 dates in functions Salvador Mainé <salvamaine@yahoo.com>
@ 2001-03-02 14:57 ` Salvador Mainé <salvamaine@yahoo.com>
1 sibling, 0 replies; 3+ messages in thread
From: Salvador Mainé @ 2001-03-02 14:57 UTC (permalink / raw)
To: pgsql-sql
The correct function is:
CREATE function anyo_hidro (date) returns int AS '
BEGIN
RETURN date_part(''month'',$1);
END;
' LANGUAGE 'plpgsql';
By the way: Do you know what 'RTFM' means?
Salvador Mainé escribió:
>
> 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
>
> Why doesn't date_part work with pl/sql functions?
>
> Thanks
>
> --
> Salvador Maine
> http://www.ronincoders.com
--
Salva
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: dates in functions
2001-03-02 14:50 dates in functions Salvador Mainé <salvamaine@yahoo.com>
@ 2001-03-05 16:13 ` George Moga <george@dsn.ro>
1 sibling, 0 replies; 3+ messages in thread
From: George Moga @ 2001-03-05 16:13 UTC (permalink / raw)
To: salva@ronincoders.com; pgsql-sql
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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2001-03-05 16:13 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-02 14:50 dates in functions Salvador Mainé <salvamaine@yahoo.com>
2001-03-02 14:57 ` Salvador Mainé <salvamaine@yahoo.com>
2001-03-05 16:13 ` George Moga <george@dsn.ro>
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