pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedExecute A String of Query
4+ messages / 4 participants
[nested] [flat]
* Execute A String of Query
@ 2002-01-23 02:12 lonh SENG <slonh@camgsm.com.kh>
2002-01-23 04:25 ` Re: Execute A String of Query Daniel Andersen <zedar@free2air.com.au>
2002-01-23 05:21 ` Re: Execute A String of Query Stephan Szabo <sszabo@megazone23.bigpanda.com>
2002-01-23 10:46 ` Re: Execute A String of Query Nick Fankhauser <nickf@ontko.com>
0 siblings, 3 replies; 4+ messages in thread
From: lonh SENG @ 2002-01-23 02:12 UTC (permalink / raw)
To: pgsql-admin
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?
TIA
Regards,
lonh
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Execute A String of Query
2002-01-23 02:12 Execute A String of Query lonh SENG <slonh@camgsm.com.kh>
@ 2002-01-23 04:25 ` Daniel Andersen <zedar@free2air.com.au>
2 siblings, 0 replies; 4+ messages in thread
From: Daniel Andersen @ 2002-01-23 04:25 UTC (permalink / raw)
To: pgsql-admin
> 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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Execute A String of Query
2002-01-23 02:12 Execute A String of Query lonh SENG <slonh@camgsm.com.kh>
@ 2002-01-23 05:21 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2 siblings, 0 replies; 4+ messages in thread
From: Stephan Szabo @ 2002-01-23 05:21 UTC (permalink / raw)
To: lonh SENG <slonh@camgsm.com.kh>; +Cc: pgsql-admin
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.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Execute A String of Query
2002-01-23 02:12 Execute A String of Query lonh SENG <slonh@camgsm.com.kh>
@ 2002-01-23 10:46 ` Nick Fankhauser <nickf@ontko.com>
2 siblings, 0 replies; 4+ messages in thread
From: Nick Fankhauser @ 2002-01-23 10:46 UTC (permalink / raw)
To: lonh SENG <slonh@camgsm.com.kh>; pgsql-admin
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/
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2002-01-23 10:46 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-01-23 02:12 Execute A String of Query lonh SENG <slonh@camgsm.com.kh>
2002-01-23 04:25 ` Daniel Andersen <zedar@free2air.com.au>
2002-01-23 05:21 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2002-01-23 10:46 ` Nick Fankhauser <nickf@ontko.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox