Re: [SQL] SELECT and the need for cursors (?)

Поиск
Список
Период
Сортировка
От Ulf Mehlig
Тема Re: [SQL] SELECT and the need for cursors (?)
Дата
Msg-id 199810290730.IAA02038@uni-bremen.de
обсуждение исходный текст
Ответ на SELECT and the need for cursors (?)  (SQL User <sql_user@terrapin.Grateful.Net>)
Список pgsql-sql
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
  ~~~~~~~~~~~~~~~~~~~~

В списке pgsql-sql по дате отправления:

Предыдущее
От: SQL User
Дата:
Сообщение: more on what I meant by cursor issues
Следующее
От: vandeurzen luc
Дата:
Сообщение: geometric types