From: Ulf Mehlig <umehlig@uni-bremen.de>
To: sql_user@terrapin.Grateful.Net
Cc: pgsql-sql@postgreSQL.org
Cc: sql_user@terrapin.Grateful.Net
Subject: Re: [SQL] SELECT and the need for cursors (?)
Date: Thu, 29 Oct 1998 08:30:00 +0100
Message-ID: <199810290730.IAA02038@uni-bremen.de> (raw)
In-Reply-To: <199810290114.RAA29007@Grateful.Net>
References: <199810290114.RAA29007@Grateful.Net>
bryan [at] grateful [dot] net wrote:
> With MySql, when I do SELECT queries, I have never needed to know
> about or use Cursors. Now, I find that I have to use them ;-(
>
> I am not an SQL expert, so maybe there's a good reason for the need
> for cursors. Anyone have any ideas?
I'm quite new to postgresql, too, but that's my view after using it a
few weeks:
Depends on what you are going to do, you won't need to use 'cursors'
etc. Cursors are used to iterate over rows of a table, at least in
several "Embedded SQL" solutions. In postgresql there is a SQL
commandline frontend or however you call it, named "psql", from where
you can send SQL statements in interactive use, and also can load
statements from text files and so on. Output can be written to a text
file, too, so, basically you have all you need. You could use Perl or
anything for reformatting the output, e.g. No cursors necessary.
Then there are a number of programming interfaces: at least Perl, Tcl,
and C, of course, with the functions of the libpq and Embedded SQL
support. All according to the user's manual ;-) And there are ODBC
(which is supported by several languages/packages) and a Java JDBC
implementation which I have already tried. IMHO (!), the latter (JDBC)
is something you should try when you feel the need to do database
programming (e.g., write a more beautiful SQL command line interface
than psql :-) You don't need to learn about cursors, too. You get
query results wrapped in a specialized object which delivers the next
row of the result table on demand. At least the basics are not so
difficult to learn, compared to Embedded SQL (as stated before,
IMHO). The problem is, maybe, thinking more or less object-oriented
:-)
Hope it helps,
Ulf
P.S.: Read you second mail, and now I'm not so sure about having
understood your question. Cursors are needed, because -- in
database programming -- you need a concept to retrieve rows
which you'd like to process later. Cursors are one possible
concept for doing this. psql does the job for you and displays
the rows of the SQL query's result table. That's why you don't
need to care about using cursors: you do not process rows.
--
======================================================================
%%%%% Ulf Mehlig <ulf.mehlig@uni-bremen.de>
%%%%!%%% Projekt "MADAM" <umehlig@uni-bremen.de>
%%%% %!% %%%% ----------------------------------------------------
---| %%% MADAM: MAngrove | Center for Tropical Marine
||--%!% Dynamics | Biology
|| And | Fahrenheitstrasse 1
_ /||\_/\_ Management |
/ / \ \ ~~~~~~~~~~~~~~~~~ | 28359 Bremen/Germany
~~~~~~~~~~~~~~~~~~~~
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: umehlig@uni-bremen.de, sql_user@terrapin.Grateful.Net
Subject: Re: [SQL] SELECT and the need for cursors (?)
In-Reply-To: <199810290730.IAA02038@uni-bremen.de>
References: <199810290114.RAA29007@Grateful.Net> <199810290730.IAA02038@uni-bremen.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox