Re: function date_part

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: PDH(dot)KFI3(at)t-online(dot)de (Andreas Stahlhut)
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: function date_part
Date: 2000-04-11 15:29:31
Message-ID: 1024.955466971@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

PDH(dot)KFI3(at)t-online(dot)de (Andreas Stahlhut) writes:
> If I use this in a create table like
> create table primtab(
> primkey
> int4
> primary key
> default
> int4(date_part('year', 'now'::datetime) * 1000+nextval('serial_seq'))
> );
> it never works.
> ERROR: parser: parse error at or near "'"

The default-value support in 6.5.* is pretty limited, not to say broken;
I think it is probably failing on the '::datetime' part of that
expression. 7.0 copes just fine. As a workaround for 6.5, you might
try writing date_part('year', now()) instead.

> If I use it in a create function like
> create function primfnc() returns int4
> as 'select .... as primnum'
> language 'sql';
> it never works.
> ERROR: parser: parse error at or near "year"

This is probably pilot error. Did you remember to double the ' symbols
in the body of the function definition? Remember the body is itself
a single-quoted string, so any embedded quote marks must be written ''
(or \' if you prefer).

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Margarita Barvinok 2000-04-11 15:59:23 ORDER clause
Previous Message Angel Manuel Diaz Aunion 2000-04-11 15:08:43 Function