chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] Re: Doubts about the postgresql egg


From: Reed Sheridan
Subject: [Chicken-users] Re: Doubts about the postgresql egg
Date: Fri, 25 Aug 2006 13:16:13 -0500

From: Mario Domenech Goulart <address@hidden>
Subject: [Chicken-users] Doubts about the postgresql egg

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

You're not missing anything, this is a bug.  But I can't reproduce it.
When I run your test1.scm on a similar database, I get

(#("a" "b"))

which is as it should be.  I'm using Postgresql 8.1.4 and Chicken 2.3.

Also, you should be able to use pg:query-tuples to do INSERTS,
DELETES, or anything else.  pg:query-tuples and pg:query-for-each are
both just front-ends to pg:query-fold-left.

Reed Sheridan




reply via email to

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