pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: PDH.KFI3@t-online.de
Cc: pgsql-sql@postgresql.org
Subject: Re: function date_part
Date: Tue, 11 Apr 2000 11:29:31 -0400
Message-ID: <1024.955466971@sss.pgh.pa.us> (raw)
In-Reply-To: <00041115394501.03152@boerse>
References: <00041115394501.03152@boerse>

PDH.KFI3@t-online.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



view thread (2+ messages)

Message-ID: <1024.955466971@sss.pgh.pa.us>
Permalink:  ../1024.955466971@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1024.955466971@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, PDH.KFI3@t-online.de
  Subject: Re: function date_part
  In-Reply-To: <1024.955466971@sss.pgh.pa.us>
  References: <00041115394501.03152@boerse> <1024.955466971@sss.pgh.pa.us>

* 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