Re: Cursor bug?

From: "Mike G(dot)" <mike(at)thegodshalls(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Cursor bug?
Date: 2005-01-13 22:35:04
Message-ID: 20050113223504.GA16236@thegodshalls.thegodshalls
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

thank you.

I use the cursor because I really do an update against a different table based on a value from the select in the original table. I am eagerly awaiting 8.0 and the ability to issue an Update Table1 Set Table1.col = Table2.col Using (Select y from Table2)

Mike

On Thu, Jan 13, 2005 at 04:58:06PM -0500, Tom Lane wrote:
> "Mike G." <mike(at)thegodshalls(dot)com> writes:
> > I have a function that reads through one table via a cursor to make updates to a different table. There is a row in this table with a column that has a null value. The following row, in that same column, is not null.
> > When the cursor loops through the table it seems to be treating the non null row as being null. The fetch should be inserting the new non value into the variable but doesn't appear to be.
>
> You did "select count(name)", which counts the number of non-null
> occurrences of "name", ie 2. So the loop stops after two iterations,
> and never gets to the last row.
>
> I'd lose the count() step entirely and have the loop be driven solely by
> the cursor. Actually, why use a cursor at all, as opposed to a FOR IN
> SELECT loop?
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mark Dexter 2005-01-13 23:18:12 Version Control Software for Database Objects
Previous Message Tom Lane 2005-01-13 21:58:06 Re: Cursor bug?