Re: SERIAL datatype column skipping values.

Поиск
Список
Период
Сортировка
От Andreas Karlsson
Тема Re: SERIAL datatype column skipping values.
Дата
Msg-id 59e3d147-40b4-d198-3bd5-015fe4e3af20@proxel.se
обсуждение исходный текст
Ответ на SERIAL datatype column skipping values.  (Prabhat Sahu <prabhat.sahu@enterprisedb.com>)
Ответы Re: SERIAL datatype column skipping values.  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Roger Harkavy
Дата:
Сообщение: Re: Add A Glossary
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: more ALTER .. DEPENDS ON EXTENSION fixes