I have the following stored procedure:
CREATE OR REPLACE FUNCTION get_next_network()
RETURNS inet AS
$BODY$
/* get the next networkd */
DECLARE
ip inet;
BEGIN
select into ip (inet'10.41.142.0' + nextval('NetworkAddress_seq'));
return ip;
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
the sequence NetworkAddress_seq increments with 256:
CREATE SEQUENCE "NetworkAddress_seq"
INCREMENT 256
MINVALUE 256
MAXVALUE 9223372036854775807
START 256
CACHE 256;
ALTER TABLE "NetworkAddress_seq"
OWNER TO my_user;
When I call the function from pgAdmin I get: 10.41.143.0
When I call it from php/Doctrine/ORM:
$stmt = $this->_em->getConnection()->prepare("select get_next_network()");
$stmt->execute();
$stmt->fetchColumn(0);
I get something like 10.56.142.0
Why?
Edit: I checked that I'm using the same procedure by hardcoding the return value - in this case I get the same value both in pgadmin and in php. This also puts the question mark on the sequence but as I'm querying it from the procedure and not directly I would assume that no matter from where I call the get_next_network procedure it will use the same sequence... or am I wrong about this?
Edit2: The strange behavior is not related to the php side - I get the same strange results if open multiple pgAdmin SQL query windows (different DB connections?). For example: in Window1 I run
select * from get_next_network();
end get: 10.43.143.0 and if I run it again I get: 10.43.144.0, 10.43.145.0, ... etc. In Window2 - the same query returns: 10.44.143.0 and all the subsequent queries get: 10.44.144.0, 10.44.145.0,..etc.