groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Price <danprice...@gmail.com>
Subject Re: Batch Insert with Sequence?
Date Tue, 01 Dec 2015 13:13:33 GMT
Thanks, David!  I read many MSDN pages but didn't encounter that exact
syntax.  I'll give it a try and report back.  Since I'm using this insert
statement with withBatch(), I wonder how I should handle the list of values
that are being fed into it...

On Mon, Nov 30, 2015 at 11:41 PM, David Durham <david.durham.jr@gmail.com>
wrote:

> Ah, no, it looks like it's example E. from this page:
>
> https://msdn.microsoft.com/en-us/library/ff878370.aspx
>
> INSERT Test.TestTable (CounterColumn,Name)
>     VALUES (NEXT VALUE FOR Test.CountBy1, 'Syed') ;
>
> On Mon, Nov 30, 2015 at 10:38 PM, David Durham
> <david.durham.jr@gmail.com> wrote:
> > I think your insertString will have something like "insert into
> > myTable (...) values (mysequence.nextval, ?,?,?)"
> >
> > On Mon, Nov 30, 2015 at 9:33 AM, Daniel Price <danprice303@gmail.com>
> wrote:
> >> Hi all.  I've been using Groovy to batch insert data into SQL Server,
> and it
> >> works very well.  The syntax I've been using is:
> >>
> >> //batch insert
> >> int dbThrottle = 25000
> >> db.withTransaction{
> >>    def result = db.withBatch(dbThrottle, insertString){ ps ->
> >>       output.each{
> >>          ps.addBatch(it)
> >>        }
> >>    }
> >> }
> >>
> >> This code is used to insert data from list 'output' into my Sql Server
> DB.
> >> The 'insertString' is just the typical insert statement dynamically
> derived
> >> from the target table and columns.
> >>
> >> I now have a need to use a sequence generator to populate one or more
> >> columns in some tables.  I can do this by putting sequence numbers in a
> list
> >> and inserting such sequence lists into my 'output' data list, but this
> is
> >> very slow.  Is there a way I can include the 'NEXT VALUE FOR' sequence
> query
> >> in the batch insert query so that it is evaluated during batch insert?
> Will
> >> this be any faster?
> >>
> >> Thanks!
> >> D
>

Mime
View raw message