Thread: Operations widh CURSORS

Operations widh CURSORS

From
Marcos Barreto de Castro
Date:
Hi,

  Is it possible to declare 2 cursors in the same
transaction?
  I am issuing a "BEGIN WORK" statement, after that I
am issuing "DECLARE c_cursor FOR SELECT * FROM table".
When, after that, I issue "DECLARE c_cursor1 FOR
SELECT COUNT(*) FROM table" I get a segmentation
fault.
  Is there a way to avoid this and still be able to
open 2 cursors in the same transaction?
  Thanks a lot.

Marcos Castro
email: mbdecastro@yahoo.com

__________________________________________________
Do You Yahoo!?
Yahoo! Photos -- now, 100 FREE prints!
http://photos.yahoo.com

recipe database

From
moebius@ip-solutions.net
Date:
Hey All,
  I was wondering if anyone had an example of writing a recipe database
that I could take a look at. I am by no means a db programmer but I would
like to give it a shot. What i am trying to do is somthing like:
Pie              $3.70
 1/4 cup sugar @ $1.10
 1 pie crust   @ $.60
 3 apples      @ $2.00
Any help would be greatly appreciated,
Thanks,

Harry Hoffman
Manager - Information Technology
Restaurants Unlimited Inc.
206.634.3082 x. 270



Re: Operations widh CURSORS

From
Tom Lane
Date:
Marcos Barreto de Castro <mbdecastro@yahoo.com> writes:
>   I am issuing a "BEGIN WORK" statement, after that I
> am issuing "DECLARE c_cursor FOR SELECT * FROM table".
> When, after that, I issue "DECLARE c_cursor1 FOR
> SELECT COUNT(*) FROM table" I get a segmentation
> fault.

Seems to work fine for me ... what version are you using?

            regards, tom lane


regression=# create table foo(f1 int);
CREATE
regression=# insert into foo values(1);
INSERT 277673 1
regression=# insert into foo values(2);
INSERT 277674 1
regression=# insert into foo values(3);
INSERT 277675 1
regression=# insert into foo values(4);
INSERT 277676 1
regression=# begin;
BEGIN
regression=# DECLARE c_cursor CURSOR FOR SELECT * FROM foo;
SELECT
regression=# DECLARE c_cursor1 CURSOR FOR SELECT count(*) FROM foo;
SELECT
regression=# fetch 1 from c_cursor;
 f1
----
  1
(1 row)

regression=# fetch 1 from c_cursor1;
 count
-------
     4
(1 row)

regression=# fetch 1 from c_cursor;
 f1
----
  2
(1 row)

regression=# fetch 1 from c_cursor;
 f1
----
  3
(1 row)

regression=# fetch 1 from c_cursor;
 f1
----
  4
(1 row)

regression=# fetch 1 from c_cursor1;
 count
-------
(0 rows)

regression=# fetch 1 from c_cursor;
 f1
----
(0 rows)

regression=# end;
COMMIT

Re: Operations widh CURSORS

From
Jurgen Defurne
Date:
Marcos Barreto de Castro wrote:

> Hi,
>
>   Is it possible to declare 2 cursors in the same
> transaction?
>   I am issuing a "BEGIN WORK" statement, after that I
> am issuing "DECLARE c_cursor FOR SELECT * FROM table".
> When, after that, I issue "DECLARE c_cursor1 FOR
> SELECT COUNT(*) FROM table" I get a segmentation
> fault.
>   Is there a way to avoid this and still be able to
> open 2 cursors in the same transaction?
>   Thanks a lot.
>
> Marcos Castro
> email: mbdecastro@yahoo.com
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Photos -- now, 100 FREE prints!
> http://photos.yahoo.com

You do not need to declare your cursors inside your transaction. A
cursor
is like a kind of data structure : you declare it and then you use it
at will whenever you need it.

<Declare cursors here>

BEGIN WORK;

-- Open cursors here

-- Work with cursors here

-- COMMIT or ROLLBACK, depending on the outcome of your program

Jurgen Defurne
defurnj@glo.be




Re: recipe database

From
Lincoln Yeoh
Date:
Shouldn't be a problem, but the approach depends on how you would like to
access the data later.

Will you be storing the methods/steps as well?

Will you need to link it (loosely) to something else - say procurement and
sales? Or it's just recipes.

Because it's quite different if you later want to find out:
We sold X number of various products.
Based on the recipes we should have used Y raw materials.
Compare this with what we're buying. etc etc.

vs.
I just want to look up recipes given some keywords.

Cheerio,

Link.
At 09:06 AM 02-06-2000 -0700, moebius@ip-solutions.net wrote:
>Hey All,
>  I was wondering if anyone had an example of writing a recipe database
>that I could take a look at. I am by no means a db programmer but I would
>like to give it a shot. What i am trying to do is somthing like:
>Pie              $3.70
> 1/4 cup sugar @ $1.10
> 1 pie crust   @ $.60
> 3 apples      @ $2.00
>Any help would be greatly appreciated,
>Thanks,
>
>Harry Hoffman
>Manager - Information Technology
>Restaurants Unlimited Inc.
>206.634.3082 x. 270
>
>
>
>