From: | Andreas Karlsson <andreas(at)proxel(dot)se> |
---|---|
To: | Prabhat Sahu <prabhat(dot)sahu(at)enterprisedb(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: SERIAL datatype column skipping values. |
Date: | 2020-03-11 14:01:41 |
Message-ID: | 59e3d147-40b4-d198-3bd5-015fe4e3af20@proxel.se |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 3/11/20 11:15 AM, Prabhat Sahu wrote:
> Hi all,
> Please check the below behavior for the "SERIAL" datatype.
>
> [...]
>
> In this above case, the serial column "c2" is skipping the value "4" in
> select output.
> Is this an expected behavior?
Curious, it seems like DEFAULT expressions of a table are executed an
extra time if a set returning function is used like in your example. And
the SERIAL type is implemented using DEFAULT.
On the other hand if you use "INSERT ... SELECT" the DEFAULT expression
is only executed once per row inserted.
# CREATE FUNCTION test_default() RETURNS int LANGUAGE plpgsql AS $$
BEGIN
RAISE NOTICE 'Ran test_default()';
RETURN 42;
END
$$;
CREATE FUNCTION
# CREATE TABLE t2 (c1 int, c2 int DEFAULT test_default());
CREATE TABLE
# INSERT INTO t2 VALUES (generate_series(1,2));
NOTICE: Ran test_default()
NOTICE: Ran test_default()
NOTICE: Ran test_default()
INSERT 0 2
# INSERT INTO t2 SELECT generate_series(1,2);
NOTICE: Ran test_default()
NOTICE: Ran test_default()
INSERT 0 2
Andreas
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2020-03-11 14:06:43 | Re: Optimizer Doesn't Push Down Where Expressions on Rollups |
Previous Message | Roger Harkavy | 2020-03-11 13:40:45 | Re: Add A Glossary |