Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id EB04E9F98E6; Wed, 22 Aug 2007 08:27:07 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 44583-05; Wed, 22 Aug 2007 08:26:49 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mail.trinitydigital.com.au (mail.trinitydigital.com.au [202.134.38.99]) by postgresql.org (Postfix) with ESMTP id A4AA09F98F0; Wed, 22 Aug 2007 08:27:04 -0300 (ADT) Received: from [172.17.73.17] (C-59-101-146-253.mel.connect.net.au [59.101.146.253]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.trinitydigital.com.au (Postfix) with ESMTP id 0CCC2933A; Wed, 22 Aug 2007 21:26:45 +1000 (EST) Message-ID: <46CC1C9D.4080304@pws.com.au> Date: Wed, 22 Aug 2007 21:23:09 +1000 From: Russell Smith User-Agent: Thunderbird 2.0.0.4 (Windows/20070604) MIME-Version: 1.0 To: novice CC: pgsql-general@postgresql.org, pgsql-sql@postgresql.org Subject: Re: raw data into table process References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/1302 X-Sequence-Number: 119151 novice wrote: > I am trying to record the following entries into a table. I'm curious > to know if there's an efficient/effective way of doing this? This > entries come from an ancient datalogger (note: separated by space and > uses YY/MM/DD format to record date) > > Plain file sample.dat > > 3665 OK BS 07/08/16 07:28 > 3665 CC BS 07/08/16 07:29 > 3665 CS BS 07/08/16 07:29 > 3665 CS BS 07/08/16 07:29 > 4532 OK BS 07/08/16 07:34 > 4004 OK BS 07/08/16 07:51 > 3991 OK BS 07/08/16 07:54 > > > This is the table that I'm adding the entries to > > CREATE TABLE maintenance > ( > maintenance_id SERIAL PRIMARY KEY, > meter_id integer, > status text, > inspector text, > inspection_date timestamp with time zone, > ) > If your on unix, why not use those tools first? awk '{print $1 "\t" $2 "\t" $3 "\t" $4 " " $5}' sample.dat > sample.tab -- Begin SQL script CREATE TEMP TABLE maintenance_tmp ( meter_id integer, status text, inspector text, inspection_date timestamp with time zone ); SET datestyle='ymd'; \copy maintenance_tmp FROM sample.tab INSERT INTO maintenance (meter_id, status, inspector, inspection_date) SELECT DISTINCT meter_id, status, inspector, inspection_date FROM maintenance_tmp ORDER BY inpsection_date; ANALYZE maintenance; -- End SQL Script [snip] > Any thoughts and suggestions welcome. > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend >