chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Doubts about the postgresql egg


From: Mario Domenech Goulart
Subject: [Chicken-users] Doubts about the postgresql egg
Date: 24 Aug 2006 22:42:13 -0300
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

Hello,

I'm trying to use the postgres egg and I have some doubts about how to
use it.

A basic (maybe silly) question: if I just want to perform an
`insert', `create table' or something that doesn't return data
from tables, do I have to use something like:

  (pg:query-for-each
   (lambda (_) _)
   "insert something into my-table" conn)

or is there a better way to do that?

Now a problem I'm having with pg:query-tuples (chicken 2.41). I have a
simple database:

$ psql test
Welcome to psql 8.0.4, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

test=> \d test
    Table "public.test"
 Column | Type | Modifiers
--------+------+-----------
 v1     | text |
 v2     | text |

test=> select * from test;
 v1 | v2
----+----
 a  | b
(1 row)


If I try the following code:

,----[ test.scm ]
| #!/usr/bin/csi -script
| 
| (use postgresql)
| 
| (let ((db (pg:connect '((dbname . "test")))))
|     (pg:query-tuples "select * from test" db)
|     (pg:close db))
`----

I get:

$ ./test.scm
Error: Wrong seed count
(expected 1)
(got 0)

        Call history:

        <eval>          (##sys#require (quote postgresql))
        <eval>          (pg:connect (quote ((dbname . "test"))))
        <eval>          (pg:query-tuples "select * from test" db)       <--


I get the expected result when I use pg:query-for-each:

,----[ test2.scm ]
| #!/usr/bin/csi -script
| 
| (use postgresql)
| 
| (let ((db (pg:connect '((dbname . "test")))))
|     (pg:query-for-each
|      (lambda (tuple)
|        (pp tuple))
|      "select * from test" db)
|     (pg:close db))
`----

$ ./test2.scm
#("a" "b")

Is there something I'm missing about pg:query-tuples?

Best wishes,
Mario




reply via email to

[Prev in Thread] Current Thread [Next in Thread]