Re: affected rows count

Lists: pgsql-hackers
From: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
To: PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: affected rows count
Date: 2008-12-22 07:51:19
Message-ID: 07BB16B8-C37C-4FCB-B136-B653841FA936@pointblue.com.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hey folks,

It doesn't stop to bug me, that postgres will return 0 number of
affected rows, if table is triggered.
Now, question is - is this fixable, but no one cares, or is it some
sort of a design/implementation flaw and we just have to live with it.


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
Cc: PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: affected rows count
Date: 2008-12-22 20:07:52
Message-ID: 200812222007.mBMK7q602622@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Grzegorz Jaskiewicz wrote:
> Hey folks,
>
> It doesn't stop to bug me, that postgres will return 0 number of
> affected rows, if table is triggered.
> Now, question is - is this fixable, but no one cares, or is it some
> sort of a design/implementation flaw and we just have to live with it.

Would you show us an example of your problem?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>, PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: affected rows count
Date: 2008-12-22 20:16:56
Message-ID: 1229977016.5854.17.camel@dell.linuxdev.us.dell.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, 2008-12-22 at 15:07 -0500, Bruce Momjian wrote:
> Grzegorz Jaskiewicz wrote:
> > Hey folks,
> >
> > It doesn't stop to bug me, that postgres will return 0 number of
> > affected rows, if table is triggered.
> > Now, question is - is this fixable, but no one cares, or is it some
> > sort of a design/implementation flaw and we just have to live with it.
>
> Would you show us an example of your problem?
>

This may not be the problem he's talking about, but it's bothered me for
a while that there is no way to control the value returned for the
affected rows.

For instance, if you have an updatable view that uses a function that
updates a table in a remote database, it would be nice to be able to
pass that value back to the client.

Regards,
Jeff Davis


From: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: affected rows count
Date: 2008-12-22 21:28:14
Message-ID: 4B57653C-546F-4FFD-B542-42D38F2861A8@pointblue.com.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On 2008-12-22, at 21:07, Bruce Momjian wrote:

> Grzegorz Jaskiewicz wrote:
>> Hey folks,
>>
>> It doesn't stop to bug me, that postgres will return 0 number of
>> affected rows, if table is triggered.
>> Now, question is - is this fixable, but no one cares, or is it some
>> sort of a design/implementation flaw and we just have to live with
>> it.
>
> Would you show us an example of your problem?
Dunno what's wrong with me lately. I was under impression, that about
1/2 year ago on 8.1 I wasn't able to get row count anymore if there
was a trigger on a table. Well, affected row count would be always 0
than.
But trying now on cvs head, it all works great. heh, I am terribly
sorry...


From: "Dawid Kuroczko" <qnex42(at)gmail(dot)com>
To: "Bruce Momjian" <bruce(at)momjian(dot)us>
Cc: "Grzegorz Jaskiewicz" <gj(at)pointblue(dot)com(dot)pl>, "PostgreSQL-development Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: affected rows count
Date: 2008-12-22 21:35:31
Message-ID: 758d5e7f0812221335l2ffeb02bwed563c11f23472ef@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Dec 22, 2008 at 9:07 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> Grzegorz Jaskiewicz wrote:
>> Hey folks,
>>
>> It doesn't stop to bug me, that postgres will return 0 number of
>> affected rows, if table is triggered.
>> Now, question is - is this fixable, but no one cares, or is it some
>> sort of a design/implementation flaw and we just have to live with it.
>
> Would you show us an example of your problem?

If I understand the problem correctly:

atlantis=> CREATE TABLE foo (i int PRIMARY KEY, t text);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"foo_pkey" for table "foo"
CREATE TABLE
atlantis=> CREATE TABLE bar (i int PRIMARY KEY, t text);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"bar_pkey" for table "bar"
CREATE TABLE
atlantis=> INSERT INTO foo (i,t) SELECT n, '#'||n FROM
generate_series(0,99) AS g(n);
INSERT 0 100
atlantis=> INSERT INTO bar (i) SELECT i FROM foo;
INSERT 0 100
atlantis=> UPDATE foo SET t='##'||t;
UPDATE 100

atlantis=> CREATE OR REPLACE FUNCTION foo_trigger() RETURNS trigger AS
$$ BEGIN UPDATE bar SET t=NEW.t WHERE i=NEW.i; RETURN NULL; END; $$
LANGUAGE plpgsql;
atlantis=> CREATE TRIGGER foo_update BEFORE UPDATE ON foo FOR EACH ROW
EXECUTE PROCEDURE foo_trigger();
CREATE TRIGGER
CREATE FUNCTION
atlantis=> UPDATE foo SET t='##'||t;
UPDATE 0
^^^^^^^^^^

Grzegorz means such a situation. Personally I understand the current
behavior to be correct -- since no row in that table is updated.

OTOH when you use triggers for emulating table partitioning it leads
to confusion (parent table was not updated, but the child table is
(or isn't because there were really 0 rows updated -- you can't really tell)).

Best regards,
Dawid
--
.................. ``The essence of real creativity is a certain
: *Dawid Kuroczko* : playfulness, a flitting from idea to idea
: qnex42(at)gmail(dot)com : without getting bogged down by fixated demands.''
`..................' Sherkaner Underhill, A Deepness in the Sky, V. Vinge


From: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
To: "Dawid Kuroczko" <qnex42(at)gmail(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "PostgreSQL-development Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: affected rows count
Date: 2008-12-22 21:38:37
Message-ID: 83BCFEB1-2941-4A28-9063-A81544DD33B6@pointblue.com.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On 2008-12-22, at 22:35, Dawid Kuroczko wrote:
>
>
> atlantis=> CREATE OR REPLACE FUNCTION foo_trigger() RETURNS trigger AS
> $$ BEGIN UPDATE bar SET t=NEW.t WHERE i=NEW.i; RETURN NULL; END; $$
> LANGUAGE plpgsql;
> atlantis=> CREATE TRIGGER foo_update BEFORE UPDATE ON foo FOR EACH ROW
> EXECUTE PROCEDURE foo_trigger();
> CREATE TRIGGER
> CREATE FUNCTION
> atlantis=> UPDATE foo SET t='##'||t;
> UPDATE 0
> ^^^^^^^^^^
>
> Grzegorz means such a situation. Personally I understand the current
> behavior to be correct -- since no row in that table is updated.

that's not quite what I meant. It is correct behavior in this
situation - since we didn't update anything.
Like I said, it is my bad - I should have tested it before emailing -
hackers... So far my ratio of useful emails here is very low. :/