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

update the same tuple in one command twice

From: "terry" <94487509(at)qq(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: update the same tuple in one command twice
Date: 2010-03-16 07:15:29
Message-ID: hnnb78$2svu$1@news.hub.org (view raw or flat)
Thread:
Lists: pgsql-bugs
In one command, why can we update the same tuple for twice?
And the result is not predicated!!

Welcome to psql 8.3.3, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

TEST=# CREATE TABLE t1(a INT, b INT);
CREATE TABLE
TEST=# CREATE TABLE t2(c INT, d INT, e INT);
CREATE TABLE
TEST=# INSERT INTO t1 VALUES(1, 1);
INSERT 0 1
TEST=# INSERT INTO t1 VALUES(2, 3);
INSERT 0 1
TEST=# INSERT INTO t2 VALUES(2, 203, 212);
INSERT 0 1
TEST=# INSERT INTO t2 VALUES(2, 324, 1342);
INSERT 0 1
TEST=# INSERT INTO t2 VALUES(3, 342, 214);
INSERT 0 1
TEST=# update t1 set a = t2.d from t2 where a=t2.c;
UPDATE 1
TEST=# select * from t1;
  a  | b
-----+---
   1 | 1
 203 | 3
(2 rows)

why not is:
  a  | b
-----+---
   1 | 1
 324 | 3
(2 rows)

TEST=# select * from t2;
 c |  d  |  e
---+-----+------
 2 | 203 |  212
 2 | 324 | 1342
 3 | 342 |  214
(3 rows)

TEST=# 



Responses

pgsql-bugs by date

Next:From: Peter EisentrautDate: 2010-03-16 11:02:08
Subject: Re: Error when lock conflict on REPLACE function
Previous:From: beulah prasanthiDate: 2010-03-16 07:06:10
Subject: could not load library

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