Re: not fetching all query results

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Radim Kolar <hsn(at)filez(dot)com>
Cc: PostgreSQL JDBC <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: not fetching all query results
Date: 2012-07-17 20:05:14
Message-ID: CADK3HHLOhLMBcMymZQAkWKubfvQKpkcZpaePH9yQJq-V0Ksucg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Radim,

As per our docs
http://jdbc.postgresql.org/documentation/91/query.html#fetchsize-example

You need to do the select inside a transaction

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On Tue, Jul 17, 2012 at 3:49 PM, Radim Kolar <hsn(at)filez(dot)com> wrote:
> with 5m result set you can set fetchsize to any value it has no effect
>
> @GrabConfig(systemClassLoader = true)
> @Grab(group='postgresql', module='postgresql', version='8.3-603.jdbc4')
> @Grab(group='commons-lang', module='commons-lang', version='2.6')
>
> import groovy.sql.Sql
> import org.apache.commons.lang.math.RandomUtils
>
> def sql=Sql.newInstance("jdbc:postgresql://localhost/grails", "postgres",
> "postgres")
> sql.setCacheStatements(true)
>
> /*
> sql.withTransaction {
> for (i in 1..5000000 ) {
> sql.executeUpdate("insert into public.test (a) values (?)",
> [RandomUtils.nextLong()])
> }
> }
> */
>
> def c = sql.getConnection()
> def s = c.createStatement()
> s.setFetchSize(100000)
> def r = s.executeQuery("select * from public.test")
> def cnt = 0
> while (r.next()) {
> cnt++
> }
>
> println "${cnt} rows."
>
> sql.close()
>
>

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Radim Kolar 2012-07-17 21:00:07 Re: not fetching all query results
Previous Message Radim Kolar 2012-07-17 19:49:00 Re: not fetching all query results