pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
create function problem
3+ messages / 3 participants
[nested] [flat]

* create function problem
@ 2004-03-16 04:02  Thomas Leung <thomasleung@hotmail.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Thomas Leung @ 2004-03-16 04:02 UTC (permalink / raw)
  To: pgsql-admin

I want to index my table using the year of the date. So I create the 
following function.

create function to_year(date) returns varchar as '
declare
  str varchar;
  begin
    str := to_char($1, "YYYY");
    return str;
  end;
' language 'plpgsql' with (iscachable, isstrict);

But I face the problem as follow
select to_year(current_date);
WARNING:  Error occurred while executing PL/pgSQL functions to_year
WARNING:  line 4 at assignment
ERROR:  Attribute "YYYY" not found

Anybody can help? Thanks.

_________________________________________________________________
Linguaphone :  Learning English? Get Japanese lessons for FREE 
http://go.msnserver.com/HK/30476.asp




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: create function problem
@ 2004-03-19 14:43  Stephan Szabo <sszabo@megazone.bigpanda.com>
  parent: Thomas Leung <thomasleung@hotmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Stephan Szabo @ 2004-03-19 14:43 UTC (permalink / raw)
  To: Thomas Leung <thomasleung@hotmail.com>; +Cc: pgsql-admin

On Tue, 16 Mar 2004, Thomas Leung wrote:

> I want to index my table using the year of the date. So I create the
> following function.
>
> create function to_year(date) returns varchar as '
> declare
>   str varchar;
>   begin
>     str := to_char($1, "YYYY");
>     return str;
>   end;
> ' language 'plpgsql' with (iscachable, isstrict);
>
> But I face the problem as follow
> select to_year(current_date);
> WARNING:  Error occurred while executing PL/pgSQL functions to_year
> WARNING:  line 4 at assignment
> ERROR:  Attribute "YYYY" not found
>
> Anybody can help? Thanks.

I think you're going towant doubled single quotes (''YYYY'') not double
quotes.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: create function problem
@ 2004-03-19 15:25  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Thomas Leung <thomasleung@hotmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2004-03-19 15:25 UTC (permalink / raw)
  To: Thomas Leung <thomasleung@hotmail.com>; +Cc: pgsql-admin

"Thomas Leung" <thomasleung@hotmail.com> writes:
>     str := to_char($1, "YYYY");

> ERROR:  Attribute "YYYY" not found

Double and single quotes are not interchangeable.  Here you have written
an identifier, not a string literal.  You'll need
     str := to_char($1, ''YYYY'');
or
     str := to_char($1, \'YYYY\');
according to taste.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2004-03-19 15:25 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-03-16 04:02 create function problem Thomas Leung <thomasleung@hotmail.com>
2004-03-19 14:43 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
2004-03-19 15:25 ` Tom Lane <tgl@sss.pgh.pa.us>

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