🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.bazy-danych
Article #195467

Postgresql rule typ serial

#195467
From: Cezary Grądys
Date: Mon, 01 Jan 2018 13:30
30 lines
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>
Technical Details
Message-ID: <5a4a3812$0$640$65785112@news.neostrada.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!peer02.am4!peer.am4.highwinds-media.com!peer04.fr7!futter-mich.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-a-01.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!peer02.am4!peer.am4.highwinds-media.com!peer04.fr7!futter-mich.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-a-01.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
Newsgroups: pl.comp.bazy-danych
X-Mozilla-News-Host: news://news.neostrada.pl:119
From: Cezary Grądys <czarekgr@wa.onet.pl>
Subject: Postgresql rule typ serial
Date: Mon, 1 Jan 2018 14:30:58 +0100
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0
MIME-Version: 1.0
Lines: 30
Message-ID: <5a4a3812$0$640$65785112@news.neostrada.pl>
Organization: Telekomunikacja Polska
NNTP-Posting-Host: 37.47.39.10
X-Trace: 1514813458 unt-rea-b-01.news.neostrada.pl 640 37.47.39.10:15355
X-Complaints-To: abuse@news.neostrada.pl
X-Received-Body-CRC: 4049187169
X-Received-Bytes: 1901
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit