Explicite typecasting of functions

From: Andreas Tille <tillea(at)rki(dot)de>
To: PostgreSQL SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Explicite typecasting of functions
Date: 2002-08-14 09:30:25
Message-ID: Pine.LNX.4.44.0208141123010.8253-100000@wr-linux02.rki.ivbb.bund.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,

I want to insert new data into a table with increasing data set ids.
The table has two separate "regions" of data: Those with Ids below
1000000 and other. If I want to create a new Id in the "lower region"
I tried the following (simplified example):

CREATE TABLE Items (
Id int DEFAULT NextItem()
) ;

/*
ERROR: Function 'nextitem()' does not exist
Unable to identify a function that satisfies the given argument types
You may need to add explicit typecasts
*/

CREATE FUNCTION NextItem() RETURNS INT4
AS 'select max(Id)+1 from Items where Id < 1000000;'
LANGUAGE 'sql';

I did not found any trace of documentation how to do an explicit typecast
for the function. Defining the function first fails because:

ERROR: Relation "items" does not exist

Any hint to solve this kind of chicken-egg-problem?

Kind regards

Andreas.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2002-08-14 11:10:29 Re: Explicite typecasting of functions
Previous Message Richard Huxton 2002-08-14 09:18:38 Re: concurrent connections is worse than serialization?