Thread: Disapointed !!

Disapointed !!

From
François LODIER
Date:
Hi, all
I am always on this problem of calling a function from a c libraire in psql  and I found somethig very strange. In order to make me understand I will try to describe you all the stuff :

I have got two databases which can be on the same or on different computer. One I call the client database and the other the server database. The server database manages the mail of some entries in the client database (which contains the information about the user).
So I wanted to create trigger in order to update information on the server databse when a change is done on the client database.
This trigger on the client should call a c function that make the chage on the server database.

The problem is that when I call this function from the trigger it makes a strange request on the client database and the server postmaster blocks at the "Initpostgres". To make sure it was not the trigger I created, with the same sources, a simple sql function, and had the same result that I had whith the trigger.

So I wrote a very short c function that calls the library that I created for postgres to make sure that the library works fine. And it does !

I must say that I am totally dispointed. If any one could help he would be welcome.

-- 
--------------------------------
François Lodier             .   _
.                         __     .
.                        ..     ...
zentak@agisphere.com      .  __  .
Ouais! Et pourquoi ??      ... .
---------------------------------
 

Sequence bug or feature?

From
"rob"
Date:
It appears that sequence.last_value and nextval('sequence') are out of sync
when first created.  My comments below are in [brackets].  Is this by design
or is this a bug?  Does this conform to SQL92?  TIA.

--rob


partner=> create SEQUENCE junk;
CREATE
partner=> select junk.last_value;
 last_value
------------
          1       [ last value is one  . . . Thought it would be 0, but
that's no big deal]
(1 row)

partner=> select nextval('junk');
 nextval
---------
       1        [If last value was one then why is nextval() not 2 ?!?!?]
(1 row)

partner=> select junk.last_value;
 last_value
------------
          1       [Consistent, but I expected 2 as described above]
(1 row)

partner=> select nextval('junk');
 nextval
---------
       2           [Ahhh now that's better]
(1 row)

partner=> select junk.last_value;
 last_value
------------
          2        [Just what I expected . . . ]
(1 row)



Re: Sequence bug or feature?

From
Tom Lane
Date:
"rob" <rob@cabrion.com> writes:
> It appears that sequence.last_value and nextval('sequence') are out of sync
> when first created.  My comments below are in [brackets].  Is this by design
> or is this a bug?  Does this conform to SQL92?  TIA.

It's by design.  Note the is_called flag, which might be better named
ever_advanced or some such.  The initial state is last_value = initial
value, is_called = false.  The first nextval changes is_called to true;
subsequent ones increment last_value.  So last_value is the last value
assigned only if a value has ever been assigned, ie, is_called is true.

This is a little bit baroque, agreed.  I think the idea was to allow
sequences to start at MININT without creating arithmetic-overflow
issues.

            regards, tom lane