You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have stored procedure where I insert data to table and returning primary key of inserted data.
When I write select * from PROCEDURE P left outer join TABLE T on http://T.PK = http://P.PK then in Firebird 3.0.6 T is null, but in 2.5 T containg inserted data
When I create sql query in the same transaction to TABLE T - data is returned
example:
set term ^;
create table TEST_TABLE (
PKID integer,
TEXT varchar(10),
constraint TEST_TABLE_PKID primary key (PKID))^
create or alter procedure TEST_PROCEDURE (text varchar(10))
returns (PKID integer)
as
begin
select coalesce (max(PKID), 0) + 1
from TEST_TABLE
into :pkid;
insert into TEST_TABLE (PKID, TEXT) values (:pkid, :text);
suspend;
end
^
set term ;^
this query in FB 3.0.6 return null but in 2.5.9 return Hi
select T.TEXT
from TEST_PROCEDURE('Hi') P
left outer join TEST_TABLE T on T.PKID = P.PKID;
The text was updated successfully, but these errors were encountered:
As designed. Query cannot see its own changes in tables. Otherwise insert-select on the same table would be endless (as it was in version 2.5 which was a bug).
Your way of generating IDs is not safe under concurrent updates: it will generate identical ids. Instead use an identity column (or a sequence + trigger), together with INSERT ... RETURNING ...
This is not a bug, but the correct behavior that can be tested in other DBMSs. The cursor should not see its changes. Earlier versions did not work correctly.
Never use stored procedures with side effects in JOIN queries. Optimizer paths are not confusing, and the result of such queries is not predictable.
Submitted by: Tomas Beran (berant)
I have stored procedure where I insert data to table and returning primary key of inserted data.
When I write select * from PROCEDURE P left outer join TABLE T on http://T.PK = http://P.PK then in Firebird 3.0.6 T is null, but in 2.5 T containg inserted data
When I create sql query in the same transaction to TABLE T - data is returned
example:
set term ^;
create table TEST_TABLE (
PKID integer,
TEXT varchar(10),
constraint TEST_TABLE_PKID primary key (PKID))^
create or alter procedure TEST_PROCEDURE (text varchar(10))
returns (PKID integer)
as
begin
select coalesce (max(PKID), 0) + 1
from TEST_TABLE
into :pkid;
insert into TEST_TABLE (PKID, TEXT) values (:pkid, :text);
suspend;
end
^
set term ;^
this query in FB 3.0.6 return null but in 2.5.9 return Hi
select T.TEXT
from TEST_PROCEDURE('Hi') P
left outer join TEST_TABLE T on T.PKID = P.PKID;
The text was updated successfully, but these errors were encountered: