From: | Andreas Tille <tillea(at)rki(dot)de> |
---|---|
To: | PostgreSQL SQL <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Explicite typecasting of functions |
Date: | 2002-08-15 07:08:39 |
Message-ID: | Pine.LNX.4.44.0208150851320.8253-100000@wr-linux02.rki.ivbb.bund.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Wed, 14 Aug 2002 Richard Huxton wrote:
> > CREATE TABLE Items (
> > Id int DEFAULT NextItem()
>
> > CREATE FUNCTION NextItem() RETURNS INT4
> > AS 'select max(Id)+1 from Items where Id < 1000000;'
> > LANGUAGE 'sql';
>
> > ERROR: Relation "items" does not exist
> >
> > Any hint to solve this kind of chicken-egg-problem?
>
> Your solution is not safe anyway - you could end up with two processes trying
> to insert the next value.
While you are perfectly right in principle I can be sure that this can not
happen in this application.
> Can I suggest two sequences: item_low_seq and item_high_seq? Set the initial
> value of each to 1,000,000 and 99,000,000 (or whatever) and then use
> whichever sequence is appropriate.
>
> In the example above you'd want something like:
> id int not null default nextval('item_low_seq')
In fact I want to let PostgreSQL manage only the Ids of the 'lower region'
via sequences/functions whatever. The 'higher region' is imported from
an external source and contains explicite Ids.
But anyway for academic reasons: What means adding 'explicit typecast'
of a func???
I was not able to find this term in the docs.
Kind regards
Andreas.
From | Date | Subject | |
---|---|---|---|
Next Message | Andreas Tille | 2002-08-15 07:13:00 | Re: Explicite typecasting of functions |
Previous Message | Masaru Sugawara | 2002-08-15 02:17:15 | Re: Need Help for select |