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

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: szittya314(at)gmail(dot)com
Subject: BUG #17554: when i use rule on table which have serial column, the nextval exec twice.
Date: 2022-07-18 09:55:26
Message-ID: 17554-3a1ae834cdb577ac@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 17554
Logged by: Szabolcs Klement
Email address: szittya314(at)gmail(dot)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

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Julien Rouhaud 2022-07-18 10:19:55 Re: BUG #17552: pg_stat_statements tracks internal FK check queries when COPY used to load data
Previous Message hubert depesz lubaczewski 2022-07-18 09:43:30 Re: Excessive number of replication slots for 12->14 logical replication