From slonh@camgsm.com.kh Wed Jan 23 02:22:29 2002 Received: from mailmx.camgsm.com.kh ([203.144.65.11]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g0N2MQl85317 for ; Tue, 22 Jan 2002 21:22:29 -0500 (EST) (envelope-from slonh@camgsm.com.kh) Received: from idlonh ([23.0.160.5]) by mailmx.camgsm.com.kh (8.10.2/8.10.2/SuSE Linux 8.10.0-0.3) with SMTP id g0N2E5T21212 for ; Wed, 23 Jan 2002 09:14:05 +0700 X-Authentication-Warning: mailmx.camgsm.com.kh: Host [23.0.160.5] claimed to be idlonh Message-ID: <014801c1a3b3$6f4c9d50$320010ac@idlonh> From: "lonh SENG" To: Subject: Execute A String of Query Date: Wed, 23 Jan 2002 09:12:40 +0700 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0145_01C1A3EE.1B9925D0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Archive-Number: 200201/143 X-Sequence-Number: 3030 This is a multi-part message in MIME format. ------=_NextPart_000_0145_01C1A3EE.1B9925D0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, I am really new to Postgres. But I am familiar with SQL Server.=20 I want import data from delimiter file. How can I do this? My delimiter file is as following: uid|username ----+--------- 2974|012801849 3883|012950864 6015|012990918 4512|012854963 (4 rows) =20=20=20 Anyone has an idea? =20=20=20=20 TIA Regards, lonh ------=_NextPart_000_0145_01C1A3EE.1B9925D0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi all,
 
    I am really new to Post= gres. But=20 I am familiar with SQL Server.
 
    I want import= data=20 from delimiter file.
    How can I do this?
    My delimiter file is as= =20 following:
 
uid|username
----+---------
2974|012801849
3883|012950864=
6015|012990918
4512|012854963
(4=20 rows)
   
    Anyone has an idea?
   
    TIA
 
Regards,
 
lonh
------=_NextPart_000_0145_01C1A3EE.1B9925D0-- From zedar@free2air.com.au Wed Jan 23 04:27:34 2002 Received: from smtp02.iprimus.net.au (smtp02.iprimus.net.au [203.134.65.99]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g0N4RYl06701 for ; Tue, 22 Jan 2002 23:27:34 -0500 (EST) (envelope-from zedar@free2air.com.au) Received: from there ([203.134.187.234]) by smtp02.iprimus.net.au with Microsoft SMTPSVC(5.0.2195.4617); Wed, 23 Jan 2002 15:27:36 +1100 Content-Type: text/plain; charset="iso-8859-1" From: Daniel Andersen To: pgsql-admin@postgresql.org Subject: Re: Execute A String of Query Date: Wed, 23 Jan 2002 14:25:18 +1000 X-Mailer: KMail [version 1.3.2] References: <014801c1a3b3$6f4c9d50$320010ac@idlonh> In-Reply-To: <014801c1a3b3$6f4c9d50$320010ac@idlonh> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID: X-OriginalArrivalTime: 23 Jan 2002 04:27:36.0604 (UTC) FILETIME=[48F655C0:01C1A3C6] X-Archive-Number: 200201/145 X-Sequence-Number: 3032 > I am really new to Postgres. But I am familiar with SQL Server. > > I want import data from delimiter file. > How can I do this? > My delimiter file is as following: > > Regards, > > lonh I'm not sure if theres a neater solution out there, but I usually just pipe it through a one liner perl script and then back into psql, sorta like cat filename|perl -ne 's/\|/,/g; chop $_; print "insert into tablename values ($_);\n"'|psql databasename under the bash shell. Of course this all gets a bit messy if there are strings involved, but works nicely for numerical data. although the example given suggests you have access to the original database, in which case simply pg_dumping it is a much easier solution :) Daniel From sszabo@megazone23.bigpanda.com Wed Jan 23 05:20:55 2002 Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g0N5Ksl15436 for ; Wed, 23 Jan 2002 00:20:55 -0500 (EST) (envelope-from sszabo@megazone23.bigpanda.com) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 3DEE8D5E5; Tue, 22 Jan 2002 21:21:00 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 2F96C5BF5; Tue, 22 Jan 2002 21:21:00 -0800 (PST) Date: Tue, 22 Jan 2002 21:21:00 -0800 (PST) From: Stephan Szabo To: lonh SENG Cc: Subject: Re: Execute A String of Query In-Reply-To: <014801c1a3b3$6f4c9d50$320010ac@idlonh> Message-ID: <20020122211939.Q12547-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200201/146 X-Sequence-Number: 3033 On Wed, 23 Jan 2002, lonh SENG wrote: > Hi all, > > I am really new to Postgres. But I am familiar with SQL Server. > > I want import data from delimiter file. > How can I do this? > My delimiter file is as following: > > uid|username > ----+--------- > 2974|012801849 > 3883|012950864 > 6015|012990918 > 4512|012854963 > (4 rows) > > Anyone has an idea? Well, if you trim off the header/footer info, you can probably read the data using COPY. From nickf@ontko.com Wed Jan 23 10:50:44 2002 Received: from swan.prod.itd.earthlink.net (swan.mail.pas.earthlink.net [207.217.120.123]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g0NAoil78919 for ; Wed, 23 Jan 2002 05:50:44 -0500 (EST) (envelope-from nickf@ontko.com) Received: from 1cust174.tnt1.richmond.in.da.uu.net ([63.27.103.174] helo=nick) by swan.prod.itd.earthlink.net with smtp (Exim 3.33 #1) id 16TKzC-0004Cm-00; Wed, 23 Jan 2002 02:50:34 -0800 Reply-To: From: "Nick Fankhauser" To: "lonh SENG" , Subject: Re: Execute A String of Query Date: Wed, 23 Jan 2002 05:46:33 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 Importance: Normal In-Reply-To: <014801c1a3b3$6f4c9d50$320010ac@idlonh> X-Archive-Number: 200201/147 X-Sequence-Number: 3034 Lon- > My delimiter file is as following: > >uid|username >----+--------- >2974|012801849 Assuming all of these values are integers, and the file is called /home/lon/users.txt, this should work in psql: create table user_stuff (id Int, name BigInt); copy user_stuff from '/home/lon/test.txt' using delimiters '|'; The filename must be the full unix path, and you'll nee to remove any headers or footers that don't contain data. see this chunk of the manual for more details: http://www.postgresql.org/idocs/index.php?sql-copy.html -Nick -------------------------------------------------------------------------- Nick Fankhauser nickf@ontko.com Phone 1.765.935.4283 Fax 1.765.962.9788 Ray Ontko & Co. Software Consulting Services http://www.ontko.com/