Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 904059F9951 for ; Wed, 22 Aug 2007 01:36:20 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 36428-05 for ; Wed, 22 Aug 2007 01:36:16 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.183]) by postgresql.org (Postfix) with ESMTP id EA9FD9F98B7 for ; Wed, 22 Aug 2007 01:36:16 -0300 (ADT) Received: by wa-out-1112.google.com with SMTP id v27so61201wah for ; Tue, 21 Aug 2007 21:36:16 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition:x-google-sender-auth; b=tBsve95NB0LufCu3RTrAMZ5CDgD7153RSIhiTgxRCj0rdQInPYeyMb+d4IiynKLsCDRqM+LGvlohwrhTH05p9J8sWVNlMVBH/IkC/mpmR1Koa7wQTAaJKdqQv9Fo0Jno3zfpLPLyJ3r6mqmikPYs2isC5rnRrR+Frnc353GBt78= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition:x-google-sender-auth; b=dtxqKXmEscT3jLFWhsas4QrlEU2E9vXx0HBfn+fNnqiLlSffk42YB/EL9B5GcIFX2aX/Nzd4NaKiK/I9jkT6ew57Leg8qvt9aXxZkV0d2n8A1r4pl8WxAePz+9DDbFL/EpANGzUQv0BTH6qqG6qPSQDTYINkHS97EHB/tHqRED8= Received: by 10.114.15.1 with SMTP id 1mr250555wao.1187757375815; Tue, 21 Aug 2007 21:36:15 -0700 (PDT) Received: by 10.114.80.13 with HTTP; Tue, 21 Aug 2007 21:36:15 -0700 (PDT) Message-ID: Date: Wed, 22 Aug 2007 14:36:15 +1000 From: novice To: pgsql-general@postgresql.org, pgsql-sql@postgresql.org Subject: raw data into table process MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Google-Sender-Auth: 60f73e8b92350fe0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/1296 X-Sequence-Number: 119145 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, ) -- Begin SQL Script -- First table to dump the records in CREATE TABLE dataload1 (data text) -- Dump records using \copy \copy dataload1 FROM sample.dat -- Second table to import unique records ONLY CREATE TABLE dataload2 AS SELECT DISTINCT data FROM dataload1; -- Now I update unique records into the maintenance table -- maintenance_id is SERIAL so it will be populated automatically INSERT INTO maintenance(meter_id, status, inspector, inspection_date) SELECT substr("data", 1, 4)::int , substr("data", 8, 3) , substr("data", 21, 2) , (20||substr("data", 24, 2) ||'-'|| substr("data", 27, 2) ||'-'|| substr("data", 30, 2)||' '||substr("data", 33, 5))::timestamp as inspection_date FROM dataload2 -- So the new records will also be in timestamp order ORDER BY inspection_date ; -- Some housekeeping VACUUM FULL VERBOSE ANALYZE maintenance; -- Finally, drop the temporary tables DROP TABLE dataload1 DROP TABLE dataload2 -- End SQL script Any thoughts and suggestions welcome.