Thread View: pl.comp.bazy-danych
2 messages
2 total messages
Started by Cezary Grądys
Mon, 01 Jan 2018 13:30
Postgresql rule typ serial
Author: Cezary Grądys
Date: Mon, 01 Jan 2018 13:30
Date: Mon, 01 Jan 2018 13:30
30 lines
1981 bytes
1981 bytes
Mam taki problem, testuje sobie logowanie wpisów do tabeli:
test=# \d zlecenia
Table "public.zlecenia"
Column | Type | Modifiers
--------+---------+-------------------------------------------------------
id | integer | not null default nextval('zlecenia_id_seq'::regclass)
data | date | default (now())::date
opis | text |
Indexes:
"zlecenia_pkey" PRIMARY KEY, btree (id)
Rules:
test_rule AS
ON INSERT TO zlecenia DO INSERT INTO log (id, uzytkownik, data)
VALUES (new.id, "current_user"(), now()::date)
Problem jest taki, że pole zlecenia.id przyjmuje wartości z
przeskokiem 2, to samo w tabeli log lecz wartość o 1 większa ;)
Na pewno jest to spowodowane użyciem 'new.id', jak usunę to jest ok.
Jak to zrobić prawidłowo, żeby do tabeli log wstawić adekwatny id?
--
Cezary Grądys <czarekgr@wa.onet.pl>
Re: Postgresql rule typ serial
Author: irq
Date: Tue, 02 Jan 2018 12:57
Date: Tue, 02 Jan 2018 12:57
7 lines
1664 bytes
1664 bytes
W dniu poniedziałek, 1 stycznia 2018 14:31:01 UTC+1 użytkownik Cezary Grądys napisał: > Na pewno jest to spowodowane użyciem 'new.id', jak usunę to jest ok. > Jak to zrobić prawidłowo, żeby do tabeli log wstawić adekwatny id? triggerem: https://www.google.pl/search?q=postgresql+rule+nextval
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads