Skip site navigation (1) Skip section navigation (2)

Fwd: Strange behaviour of RULE (selecting last inserted ID of 'sequenced' column)

From: "Nikolay Samokhvalov" <samokhvalov(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Fwd: Strange behaviour of RULE (selecting last inserted ID of 'sequenced' column)
Date: 2006-08-04 09:50:42
Message-ID: e431ff4c0608040250o4b1a91f1vec6c5080b15ec1d6@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-general
I still think that this is quite strange behaviour. When I write
'...SELECT NEW.id...' I don't expect that another calling of column's
default expr will take place. I just want to have access to "id"
column of just-created row.

Any thoughts?

---------- Forwarded message ----------
From: Nikolay Samokhvalov <samokhvalov(at)gmail(dot)com>
Date: Jul 13, 2006 6:15 PM
Subject: Strange behaviour of RULE (selecting last inserted ID of
'sequenced' column)
To: PostgreSQL-general <pgsql-general(at)postgresql(dot)org>


Is this a bug?

test=> create sequence strange_seq;
CREATE SEQUENCE
test=> create table strange(id integer not null default
nextval('strange_seq') primary key, data text);
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
"strange_pkey" for table "strange"
CREATE TABLE
test=> create rule strange_rule as on insert to strange do select new.id as id;
CREATE RULE
test=> insert into strange(data) values('adas');
 id
----
  2
(1 row)

test=> select * from strange;
 id | data
----+------
  1 | adas
(1 row)

test=> insert into strange(data) values('adas');
 id
----
  4
(1 row)

test=> insert into strange(data) values('adas');
 id
----
  6
(1 row)

test=> select * from strange;
 id | data
----+------
  1 | adas
  3 | adas
  5 | adas
(3 rows)


--
Best regards,
Nikolay


-- 
Best regards,
Nikolay

In response to

Responses

pgsql-bugs by date

Next:From: Andreas GustafssonDate: 2006-08-04 12:05:24
Subject: Restoring 7.4 "pg_dumpall -o" output in 8.1 fails
Previous:From: ivankobDate: 2006-08-04 07:12:53
Subject: BUG #2563: In rules: recalculation of input expression on each access

pgsql-general by date

Next:From: Martijn van OosterhoutDate: 2006-08-04 09:54:48
Subject: Re: Locale/encoding problem/question
Previous:From: Flemming FrandsenDate: 2006-08-04 09:32:38
Subject: Re: LISTEN considered dangerous

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group