BUG #17554: when i use rule on table which have serial column, the nextval exec twice. - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #17554: when i use rule on table which have serial column, the nextval exec twice.
Date
Msg-id 17554-3a1ae834cdb577ac@postgresql.org
Whole thread Raw
Responses Re: BUG #17554: when i use rule on table which have serial column, the nextval exec twice.
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      17554
Logged by:          Szabolcs Klement
Email address:      szittya314@gmail.com
PostgreSQL version: 14.4
Operating system:   Rocky Linux release 8.5 (Green Obsidian)
Description:

Hi,
(sorry my poor english)
the problem is in 10-14 postgresql too.

this a sample what make gap in sequence:
create table aa (id serial primary key,tt text);
create or replace function fika1(p1 aa) returns boolean language sql as
$body$
    select (p1.id)::boolean;
$body$;
create or replace rule birkman as on insert to aa do select fika1(new);

insert into aa (tt) values ('uu');
select * from aa order by id;

(when inner the function isnt reference a new record, there isnt gap:
create or replace function fika1(p1 aa) returns boolean language sql as
$body$ select true;    $body$;
)

inner the function then p1.id is always X, but after the insert in the new
record is X-1;

i try with plpgsql function:
create or replace function fika1(p1 aa) returns boolean language plpgsql
as
$body$
  begin
      raise notice 'id:%', p1.id;
    return true;    --I didnt referenced the new value
  end;
$body$;

Best regards
Szabolcs


pgsql-bugs by date:

Previous
From: hubert depesz lubaczewski
Date:
Subject: Re: Excessive number of replication slots for 12->14 logical replication
Next
From: Julien Rouhaud
Date:
Subject: Re: BUG #17552: pg_stat_statements tracks internal FK check queries when COPY used to load data