X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id ED3D39DC821 for ; Wed, 8 Feb 2006 12:35:07 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 85431-05 for ; Wed, 8 Feb 2006 12:35:05 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from interscan.indicator.com (mail.indicator.be [193.121.199.3]) by postgresql.org (Postfix) with ESMTP id C6F879DC815 for ; Wed, 8 Feb 2006 12:35:03 -0400 (AST) Received: from DOMEXT-MTA by webaccess.indicator.bewith Novell_GroupWise; Wed, 08 Feb 2006 17:35:01 +0100 Message-Id: X-Mailer: Novell GroupWise Internet Agent 6.5.4 Date: Wed, 08 Feb 2006 17:34:40 +0100 From: "Bart Degryse" To: , Cc: "Bart Degryse" Subject: Re: Antw: COPY FROM Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="=__Part6C4EC8B0.1__=" X-imss-version: 2.037 X-imss-result: Passed X-imss-approveListMatch: *@indicator.be X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.208 required=5 tests=[AWL=0.206, HTML_MESSAGE=0.001, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.208 X-Spam-Level: X-Archive-Number: 200602/33 X-Sequence-Number: 7162 This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part6C4EC8B0.1__= Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi Thomas, That's the way I have it working already. With 2,700,000 records it takes = quite a lot of time though. According to the PostgreSQL manual bulk = uploads perform better with the COPY FROM statement. If only I could get = it to work... Thanks anyway. >>> "Thomas Holschen" 2006-02-08 17:30 >>> Hi Bart, Just create an ODBC Entry on your local computer, add a Refernce to ActiveX Dataobjects 2.8 oder 2.7 to your vbp Projekt, open an ADODB.connection to the Server and send SQL-Insert Statements. Little Example Private Function Insert() Dim DBS As New ADODB.Connection Dim SQLString As String DBS.Open "Provider=3DMSDASQL.1;Persist Security Info=3DFalse;Extended Properties=3DDSN=3DYourODBCDatabaseName;" =20 SQLString =3D "Insert into SomeTable (Field1,Field2,Field3) Values ('111','aaa','bbb')" DBS.Execute SQLString End Function Hope that helps... Your Mail is a little bit "unreadable" ;-) regards, Thomas. --=20 _____________________________________________ Hela Gew=FCrzwerk Hermann Laue GmbH & Co.KG EDV Thomas Holschen=20 Beimoorweg 11 22926 Ahrensburg Tel. : +49 4102/496-381 http://www.hela-food.de=20 _____________________________________________ >>> "Bart Degryse" schrieb am Mittwoch, 8. Februar 2006 um 11:03 in Nachricht : > Dear, > I need to do a bulk upload (2,600,000 records) of data into a PostgreSQL=20 > (v8.0.3) table. I'm trying to achieve this from Visual Basic with ADO and=20 > psqlODBC (v8.1.2) but I can't get it working. Currently my code looks like=20 > this. Dim conn As New ADODB.Connection Dim query As String =20 'DSN less=20 > connection query =3D "DRIVER=3D{PostgreSQL=20 > Unicode};SERVER=3D10.100.1.24;PORT=3D2345;DATABASE=3Dbigdb;BoolsAsChar=3D0;= TrueIsMin > us1=3D1;Debug=3D0;CommLog=3D0" conn.CursorLocation =3D adUseClient = =20 conn.Open=20 > query, "bad", "xxxxxxxx" query =3D "COPY dunn_main (duns, company,=20 > company_short, zip, phone, employee_number, legal_id, sic_id, source_id) " & _=20 > "FROM STDIN WITH NULL AS 'NULL' DELIMITER AS ','" =20 conn.Execute=20 > query, , adCmdText + adExecuteNoRecords + adAsyncExecute > In the driver logging I can see that it's waiting for the data now, but I=20 > can't really figure out how to deliver it. Since the source data (as a text=20 > file with fixed length fields) is only available on client side and needs=20 > some processing before being ready to import I'm using something like this to=20 > prepare the data:=20 > Private Type Dunn_Record CO_NAME As String * 90 =20 PCODE As=20 > String * 8 DUNS As String * 9 EMPS_COMP As String * 9 =20 LE=20 > As String * 2 L As String * 1 TEL_NBR As String * 14 =20 =20 > US72 As String * 4 crlf As String * 2 End Type Dim record As=20 > Dunn_Record Dim filehandle As Integer Dim filename As String =20 Dim=20 > numLines as long Dim line As Long filehandle =3D FreeFile =20 filename =3D=20 > "E:\source.txt" Open filename For Random Access Read Lock Read Write As=20 > #filehandle Len =3D Len(record) numLines =3D LOF(1) / Len(record) = =20 For line=20 > =3D 2 to numLines Get #filehandle, line, record With record =20 > query =3D query & CLng(.DUNS) & "," query =3D query & = "'" &=20 > Replace(Trim(.CO_NAME), "'", "''") & "'," query =3D query & "'" &=20 > ascii_easy(.CO_NAME) & "'," query =3D query & "'" & Trim(.PCODE) & "'," =20 > query =3D query & phone(.TEL_NBR) & "," If=20 > Len(Trim(.EMPS_COMP)) Then query =3D query & CLng(.EMPS_COMP) Else query =3D query=20 > & "NULL" query =3D query & "," If Len(Trim(.LE)) Then query=20 > =3D query & CLng(.LE) Else query =3D query & "NULL" query =3D query & "," =20 > query =3D query & CLng(.US72) & "," query =3D query = & > rs!source_id End With 'DELIVER THE DATA IN query TO THE DRIVER =20 > Next lineI have tried several methods to deliver the prepared data to the=20 > driver but without any succes.=20 > Writing to STDOUT > Private Declare Function GetStdHandle Lib "Kernel32" (ByVal nStdHandle=20 > As Long) As Long Private Declare Function WriteFile Lib "Kernel32" (ByVal=20 > hFile As Long, ByVal lpBuffer As St ring, ByVal nNumberOfBytesToWrite As Long,=20 > lpNumberOfBytesWritten As Long, lpOverlapped As Any) As Long =20 Private Const=20 > STD_OUTPUT_HANDLE =3D -11& Dim stdhandle As Long Dim llResult As Long =20 > stdhandle =3D GetStdHandle(STD_OUTPUT_HANDLE) WriteFile stdhandle, query,=20 > Len(query), llResult, ByVal 0&Writing to a socket > Dim socket As New Winsock With socket .Protocol =3D=20 > sckUDPProtocol .RemoteHost =3D "10.100.1.24" .RemotePort =3D 2345 =20 > .Connect End With socket.SendData queryExecuting it > conn.Execute queryWriting to some stream > Dim str As New Stream With str .Mode =3D adModeWrite = =20 =20 > .Open End With str.WriteText query > So basically my question is : how do I deliver the prepared data to the=20 > driver? Any help (tips, working code, example, ...) would be appreciated.=20 > Best regards Diese E-Mail enth=E4lt vertrauliche und/oder rechtlich gesch=FCtzte = Informationen. Wenn=20 Sie nicht der richtige Adressat sind oder diese E-Mail irrt=FCmlich = erhalten haben,=20 informieren Sie bitte den Absender und l=F6schen Sie diese E-Mail. Das = unerlaubte=20 Kopieren sowie die unbefugte Weitergabe dieser E-Mail ist nicht gestattet. = Aus=20 Rechts- und Sicherheitsgr=FCnden ist die in dieser E-Mail gegebene = Information nicht=20 rechtsverbindlich. This e-mail contains confidential and/or privileged information. If you = are not the=20 intended addressee or have received this e-mail in error please notify the = sender and=20 delete this e-mail. Any unauthorized copying, disclosure or distribution = of the material=20 in this e-mail is strictly forbidden. Due to legal and security reasons = the information=20 contained in this e-mail is not legally binding. --=__Part6C4EC8B0.1__= Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Description: HTML
Hi Thomas,
That's the way I have it working already. With 2,700,000 records it = takes quite a lot of time though. According to the PostgreSQL manual bulk = uploads perform better with the COPY FROM statement. If only I could get = it to work...
Thanks anyway.

>>> "Thomas Holschen" <Thomas.Holsch= en@hela-food.de> 2006-02-08 17:30 >>>
Hi Bart,

Just create an ODBC Entry on = your local computer,
add a Refernce to ActiveX Dataobjects 2.8 oder 2.7 = to your vbp
Projekt,
open an ADODB.connection to the Server and send = SQL-Insert Statements.

Little Example
Private Function Insert()    Dim DBS As New ADODB.Connection
    = Dim SQLString As String
    DBS.Open "Provider=3DMSDASQL.= 1;Persist Security Info=3DFalse;Extended
Properties=3DDSN=3DYourODBCData= baseName;"
   
    SQLString =3D = "Insert into SomeTable (Field1,Field2,Field3) Values
('111','aaa','bbb')= "
    DBS.Execute SQLString
End Function

Hope = that helps... Your Mail is a little bit "unreadable" ;-)

regards, = Thomas.





--

_________________________________= ____________
Hela Gew=FCrzwerk Hermann Laue GmbH & Co.KG
EDV
T= homas Holschen
Beimoorweg 11
22926 Ahrensburg

Tel. : +49 = 4102/496-381
http://www.hela-food.de=
_____________________________________________

>>> = "Bart Degryse" <Bart.Degryse@indicator.be> schrieb am Mittwoch, = 8.
Februar 2006
um 11:03 in Nachricht <s3e9d02f.034@webaccess.indi= cator.be>:

> Dear,
> I need to do a bulk upload = (2,600,000 records) of data into a
PostgreSQL
> (v8.0.3) table. = I'm trying to achieve this from Visual Basic with ADO
and
> = psqlODBC (v8.1.2) but I can't get it working. Currently my code looks
li= ke
> this.    Dim conn As New ADODB.Connection &= nbsp;  Dim query As String  
'DSN less
> = connection    query =3D "DRIVER=3D{PostgreSQL
>
Un= icode};SERVER=3D10.100.1.24;PORT=3D2345;DATABASE=3Dbigdb;BoolsAsChar=3D0;Tr= ueIsMin
> us1=3D1;Debug=3D0;CommLog=3D0"    conn.Curso= rLocation =3D adUseClient  
conn.Open
> query, "bad", = "xxxxxxxx"    query =3D "COPY dunn_main (duns, company, =
> company_short, zip, phone, employee_number, legal_id, sic_id,
s= ource_id) " & _
>        = ;    "FROM STDIN WITH NULL AS 'NULL' DELIMITER AS ','" =  
conn.Execute
> query, , adCmdText + adExecuteNoRecords + = adAsyncExecute
> In the driver logging I can see that it's waiting = for the data now,
but I
> can't really figure out how to deliver = it. Since the source data (as
a text
> file with fixed length = fields) is only available on client side and
needs
> some = processing before being ready to import I'm using something like
this = to
> prepare the data:
>     Private = Type Dunn_Record        CO_NAME As = String * 90      
PCODE As
> = String * 8        DUNS As String * = 9        EMPS_COMP As String * 9  =
     LE
> As String * 2   &nb= sp;    L As String * 1      &n= bsp; TEL_NBR As String * 14  
   
> = US72 As String * 4        crlf As = String * 2    End Type    Dim
record As =
> Dunn_Record    Dim filehandle As Integer  = ;  Dim filename As String  
Dim
> numLines as = long    Dim line As Long    filehandle =3D = FreeFile  
filename =3D
> "E:\source.txt"  &= nbsp; Open filename For Random Access Read Lock Read
Write As
> = #filehandle Len =3D Len(record)    numLines =3D LOF(1) / = Len(record)  
For line
> =3D 2 to numLines  =       Get #filehandle, line, record  &nb= sp;     With
record     &nb= sp;
>      query =3D query & CLng(.DUNS= ) & ","          &nbs= p; query =3D query & "'"
&
> Replace(Trim(.CO_NAME), = "'", "''") & "',"         =    query =3D query &
"'" &
> ascii_easy(.CO_NAM= E) & "',"          &n= bsp; query =3D query & "'" &
Trim(.PCODE) & "',"  =
>           query = =3D query & phone(.TEL_NBR) & ","     &nbs= p;      If
> Len(Trim(.EMPS_COMP)) Then = query =3D query & CLng(.EMPS_COMP) Else
query =3D query
> = & "NULL"          &nb= sp; query =3D query & ","       &nbs= p;    If Len(Trim(.LE))
Then query
> =3D query = & CLng(.LE) Else query =3D query & "NULL"    &n= bsp;       query =3D
query & = ","  
>        &nb= sp; query =3D query & CLng(.US72) & ","    &nbs= p;       query =3D query &

> = rs!source_id        End With  =       'DELIVER THE DATA IN query TO THE
DRIVER&= nbsp;
>   Next lineI have tried several methods to = deliver the prepared data
to the
> driver but without any = succes.
> Writing to STDOUT
>     Private = Declare Function GetStdHandle Lib "Kernel32" (ByVal
nStdHandle
> = As Long) As Long    Private Declare Function WriteFile Lib = "Kernel32"
(ByVal
> hFile As Long, ByVal lpBuffer As St
ring, = ByVal nNumberOfBytesToWrite
As Long,
> lpNumberOfBytesWritten As = Long, lpOverlapped As Any) As Long  
Private Const
> = STD_OUTPUT_HANDLE =3D -11&    Dim stdhandle As = Long    Dim llResult As
Long   
> = stdhandle =3D GetStdHandle(STD_OUTPUT_HANDLE)    WriteFile = stdhandle,
query,
> Len(query), llResult, ByVal 0&Writing to = a socket
>     Dim socket As New Winsock &nb= sp;  With socket        .Protocol = =3D
> sckUDPProtocol        = .RemoteHost =3D "10.100.1.24"        = .RemotePort
=3D 2345  
>      = .Connect    End With    socket.SendData = queryExecuting it
>     conn.Execute queryWriting= to some stream
>     Dim str As New Stream =    With str        .Mode =3D = adModeWrite    
 
> .Open  &n= bsp; End With    str.WriteText query
> So basically = my question is : how do I deliver the prepared data to
the
> = driver? Any help (tips, working code, example, ...) would be
appreciated= .
> Best regards
Diese E-Mail enth=E4lt vertrauliche und/oder = rechtlich gesch=FCtzte Informationen. Wenn
Sie nicht der richtige = Adressat sind oder diese E-Mail irrt=FCmlich erhalten haben,
informiere= n Sie bitte den Absender und l=F6schen Sie diese E-Mail. Das unerlaubte =
Kopieren sowie die unbefugte Weitergabe dieser E-Mail ist nicht = gestattet. Aus
Rechts- und Sicherheitsgr=FCnden ist die in dieser = E-Mail gegebene Information nicht
rechtsverbindlich.

This = e-mail contains confidential and/or privileged information. If you are not = the
intended addressee or have received this e-mail in error please = notify the sender and
delete this e-mail. Any unauthorized copying, = disclosure or distribution of the material
in this e-mail is strictly = forbidden. Due to legal and security reasons the information
contained = in this e-mail is not legally binding.
--=__Part6C4EC8B0.1__=--