Declaration of package constants as expressions

56 views
Skip to first unread message

Pavel Zotov

unread,
May 26, 2026, 8:14:35 AMMay 26
to firebird-devel
i have question(s) about proper usage of some functions that are mentioned in the doc/sql.extensions/README.packages.txt:

The following expressions are valid only if all operands are constants:
...
      6)  ... IIF ...

So, i run:
set bail on;
set autoterm on;
set list on;
set names utf8;
set echo on;
shell if exist r:\temp\tmp4test.fdb del r:\temp\tmp4test.fdb;
create database 'localhost:r:\temp\tmp4test.fdb' user sysdba password 'masterkey';

create or alter function standalone_abs returns smallint
as
    declare foo smallint = iif(3 > 2, 1, 0);
begin
    return 1;
end
;
create or alter package pg_const as
begin
    constant bar smallint = iif(3 > 2, 1, 0);
end
;

-- and get:
Statement failed, SQLSTATE = 42000
CREATE OR ALTER PACKAGE "PUBLIC"."PG_CONST" failed
-The constant "PUBLIC"."PG_CONST"."BAR" must be initialized by a constant expression

Is it expected ?

Pavel Zotov

unread,
May 26, 2026, 8:30:20 AMMay 26
to firebird-devel

PS. And also:

create or alter package pg_const as
begin
    constant k_nullif smallint = nullif(2,1);
end
;

Statement failed, SQLSTATE = 42000
CREATE OR ALTER PACKAGE "PUBLIC"."PG_CONST" failed
-The constant "PUBLIC"."PG_CONST"."K_NULLIF" must be initialized by a constant expression


вторник, 26 мая 2026 г. в 15:14:35 UTC+3, Pavel Zotov:

Artyom Abakumov

unread,
May 26, 2026, 10:03:10 AMMay 26
to firebird-devel
It was a bug. Fixed in the PR: https://github.com/FirebirdSQL/firebird/pull/9039

вторник, 26 мая 2026 г. в 15:30:20 UTC+3, Pavel Zotov:

Artyom Abakumov

unread,
May 27, 2026, 2:12:37 AMMay 27
to firebird-devel
The fix has been merged to the master branch.

вторник, 26 мая 2026 г. в 17:03:10 UTC+3, Artyom Abakumov:

Pavel Zotov

unread,
May 27, 2026, 3:58:41 AMMay 27
to firebird-devel


среда, 27 мая 2026 г. в 09:12:37 UTC+3, Artyom Abakumov:
The fix has been merged to the master branch.

вторник, 26 мая 2026 г. в 17:03:10 UTC+3, Artyom Abakumov:
create or alter package pg_const as
begin
    constant bar smallint = iif(3 > 2, 1, 0);
end
;
-- and get:
Statement failed, SQLSTATE = 42000
CREATE OR ALTER PACKAGE "PUBLIC"."PG_CONST" failed
-The constant "PUBLIC"."PG_CONST"."BAR" must be initialized by a constant expression

 >  The fix has been merged to the master branch.

Hm-m...

1) I've downloaded 6.0.0.1971-5d04fe7 snapshot with debug symbols
/*
Comparing files <previous_snapshot>\README.packages.txt and  <current_snapshot> \README.PACKAGES.TXT:
***** C:\FB\60CS\DOC\SQL.EXTENSIONS\README.packages.txt
  108:        1) Arithmetic operations, unary plus/minus
  109:        2) Bool As Value
  110:        3) CAST, COALESCE, CONCATENATE, DECODE, EXTRACT, UPPER/LOWER, SUBSTRING
***** C:\FB\60SS\DOC\SQL.EXTENSIONS\README.PACKAGES.TXT
  108:        1) Arithmetic operations, unary plus/minus
  109:        2) Bool As Value, Boolean compare operations
  110:        3) CAST, COALESCE, CONCATENATE, DECODE, EXTRACT, UPPER/LOWER, SUBSTRING
*****
*/

2) and run:

create or alter package pg_const as
begin
    constant bar smallint = iif(3 > 2, 1, 0);
end
;
create or alter package pg_const as
begin
    constant k_nullif int = nullif( 1, 1 );
end
;


3) and get:
Statement failed, SQLSTATE = 08006
Error reading data from the connection.
(on last statement with NULLIF).

Dump, stack-trace and snapshot are here

Artyom Abakumov

unread,
May 27, 2026, 4:30:12 AMMay 27
to firebird-devel
Sorry for the confusion, but the fix for handling NULL values ​​has not yet been included in the package and this is causing a segmentation fault.
среда, 27 мая 2026 г. в 10:58:41 UTC+3, Pavel Zotov:

Artyom Abakumov

unread,
May 27, 2026, 4:32:02 AMMay 27
to firebird-devel
has not yet been included in the package
 *has not yet been merged to the master branch

Artyom Abakumov

unread,
May 27, 2026, 7:52:40 AMMay 27
to firebird-devel
has not yet been included in the package
 *has not yet been merged to the master branch

The fix is merged now
Reply all
Reply to author
Forward
0 new messages