pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedloading and unloading rows
9+ messages / 4 participants
[nested] [flat]
* loading and unloading rows
@ 2002-11-01 00:36 Naomi Walker <nwalker@eldocomp.com>
2002-11-01 09:22 ` Re: loading and unloading rows Bhuvan A <bhuvansql@myrealbox.com>
2002-11-01 23:57 ` Re: loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
0 siblings, 2 replies; 9+ messages in thread
From: Naomi Walker @ 2002-11-01 00:36 UTC (permalink / raw)
To: pgsql-admin
This might sound silly, but I am trying something basic, and having
trouble. What I want to do is unload selected rows from a table, and load
them somewhere else.
pg_dump works great if you want the whole table. I suppose I could from
one table, dump into a temp, and then pg_dump it, but that seems silly.
I noticed in the pg_dump unloaded looking rows, with a:
COPY "table" FROM stdin;
before the rows.
So, I ran psql, did a \o to capture the output,
did a select * from table where x=y
whacked the first row in the output file, and added the COPY statement.
then did a psql dbname <file-with-rows.sql
The first column loaded, but the rest of the columns did not. I noticed
there were | delimiters in my unloaded one, and none in a pg_dump file.
This seems way too klunky, so I must be going about it all wrong. In
Informix-land I would just do a unload then a load. What is the postgresql
equivalent?
Suggestions?
Thanks,
Naomi
----------------------------------------------------------------------------
----------------------------------
Naomi Walker
Eldorado Computing, Inc
Chief Information Officer
nwalker@eldocomp.com
602-604-3100 x242
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: loading and unloading rows
2002-11-01 00:36 loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
@ 2002-11-01 09:22 ` Bhuvan A <bhuvansql@myrealbox.com>
1 sibling, 0 replies; 9+ messages in thread
From: Bhuvan A @ 2002-11-01 09:22 UTC (permalink / raw)
To: pgsql-admin
> So, I ran psql, did a \o to capture the output,
> did a select * from table where x=y
> whacked the first row in the output file, and added the COPY statement.
test_db=> \pset tuples_only -- does whacking for you
> This seems way too klunky, so I must be going about it all wrong. In
> Informix-land I would just do a unload then a load. What is the postgresql
> equivalent?
It is possible. Delimiters can be used while restoring the data file.
Null string specification can also be specified. See,
test_db=> \h COPY
for more details.
In addition you should also do some find and replace in the data file
before restoring it to another database. They are,
s/\s*|\s*//g
s/^\s*//g
Now, i bet you can able to restore.
regards,
bhuvaneswaran
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: loading and unloading rows
2002-11-01 00:36 loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
@ 2002-11-01 23:57 ` Naomi Walker <nwalker@eldocomp.com>
2002-11-02 03:39 ` Re: loading and unloading rows Bruce Momjian <pgman@candle.pha.pa.us>
2002-11-02 20:44 ` Re: loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
1 sibling, 2 replies; 9+ messages in thread
From: Naomi Walker @ 2002-11-01 23:57 UTC (permalink / raw)
To: Bhuvan A <bhuvansql@myrealbox.com>; pgsql-admin
>
>It is possible. Delimiters can be used while restoring the data file.
>Null string specification can also be specified. See,
>test_db=> \h COPY
>for more details.
The problem with COPY, I think, is that I cannot use a WHERE
statement. I'd like to just unload certain rows from a table. If I wanted
the whole table, i'll do a pg_dump or copy.
>In addition you should also do some find and replace in the data file
>before restoring it to another database. They are,
>s/\s*|\s*//g
>s/^\s*//g
Yes, sed is a fine tool, but this seems like such a fundamental need, i'm
surprised there is not better method.
Again, i'd like a way to easily unload some selected rows (select * table
where foo=X) from a table, and save them, or load them in another cluster,
etc. Short of writing them to a temp table, then pg_dumping, or some
klunk-oid mething, I do not see a clean way.
Back to the maddening crowd. Anyone at least agreed this is needed? Could
we add "where" clauses to COPY? That would be perfect.
----------------------------------------------------------------------------
----------------------------------
Naomi Walker
Eldorado Computing, Inc
Chief Information Officer
nwalker@eldocomp.com
602-604-3100 x242
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: loading and unloading rows
2002-11-01 00:36 loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
2002-11-01 23:57 ` Re: loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
@ 2002-11-02 03:39 ` Bruce Momjian <pgman@candle.pha.pa.us>
1 sibling, 0 replies; 9+ messages in thread
From: Bruce Momjian @ 2002-11-02 03:39 UTC (permalink / raw)
To: Naomi Walker <nwalker@eldocomp.com>; +Cc: Bhuvan A <bhuvansql@myrealbox.com>; pgsql-admin
Yes, agreed, it would be nice to have WHERE as part of COPY. In fact, I
like Informix's solution, which merges data in/out with INSERT/SELECT:
UNLOAD TO '/tmp/x'
SELECT *
FROM tab;
and
LOAD FROM '/tmp/x'
INSERT INTO tab;
It is tough to beat this flexibility.
---------------------------------------------------------------------------
Naomi Walker wrote:
>
> >
> >It is possible. Delimiters can be used while restoring the data file.
> >Null string specification can also be specified. See,
> >test_db=> \h COPY
> >for more details.
>
> The problem with COPY, I think, is that I cannot use a WHERE
> statement. I'd like to just unload certain rows from a table. If I wanted
> the whole table, i'll do a pg_dump or copy.
>
>
> >In addition you should also do some find and replace in the data file
> >before restoring it to another database. They are,
> >s/\s*|\s*//g
> >s/^\s*//g
>
> Yes, sed is a fine tool, but this seems like such a fundamental need, i'm
> surprised there is not better method.
>
> Again, i'd like a way to easily unload some selected rows (select * table
> where foo=X) from a table, and save them, or load them in another cluster,
> etc. Short of writing them to a temp table, then pg_dumping, or some
> klunk-oid mething, I do not see a clean way.
>
> Back to the maddening crowd. Anyone at least agreed this is needed? Could
> we add "where" clauses to COPY? That would be perfect.
>
> ----------------------------------------------------------------------------
> ----------------------------------
> Naomi Walker
> Eldorado Computing, Inc
> Chief Information Officer
> nwalker@eldocomp.com
> 602-604-3100 x242
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: loading and unloading rows
2002-11-01 00:36 loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
2002-11-01 23:57 ` Re: loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
@ 2002-11-02 20:44 ` Naomi Walker <nwalker@eldocomp.com>
2002-11-03 01:23 ` Re: loading and unloading rows Bruce Momjian <pgman@candle.pha.pa.us>
2002-11-03 23:41 ` Re: loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
1 sibling, 2 replies; 9+ messages in thread
From: Naomi Walker @ 2002-11-02 20:44 UTC (permalink / raw)
To: Bruce Momjian <pgman@candle.pha.pa.us>; Naomi Walker <nwalker@eldocomp.com>; +Cc: Bhuvan A <bhuvansql@myrealbox.com>; pgsql-admin
Exactly. My Informix background is showing. Is there a way to officially
get this put on a to do list? I'd be most appreciative of the value this adds.
Slightly off subject, is there a way to read from one cluster and insert
into a database in another cluster (local or remote)? I think I read this
is coming in the future. In Informix-land, we used to do this through a
named pipe. It was quite handy.
At 10:39 PM 11/1/02 -0500, Bruce Momjian wrote:
>Yes, agreed, it would be nice to have WHERE as part of COPY. In fact, I
>like Informix's solution, which merges data in/out with INSERT/SELECT:
>
> UNLOAD TO '/tmp/x'
> SELECT *
> FROM tab;
>
>and
>
> LOAD FROM '/tmp/x'
> INSERT INTO tab;
>
>It is tough to beat this flexibility.
>
>---------------------------------------------------------------------------
>
>Naomi Walker wrote:
> >
>
> > The problem with COPY, I think, is that I cannot use a WHERE
> > statement. I'd like to just unload certain rows from a table. If I
> wanted
> > the whole table, i'll do a pg_dump or copy.
> >
>
> > Again, i'd like a way to easily unload some selected rows (select * table
> > where foo=X) from a table, and save them, or load them in another cluster,
> > etc. Short of writing them to a temp table, then pg_dumping, or some
> > klunk-oid mething, I do not see a clean way.
> >
> > Back to the maddening crowd. Anyone at least agreed this is
> needed? Could
> > we add "where" clauses to COPY? That would be perfect.
> >
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: loading and unloading rows
2002-11-01 00:36 loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
2002-11-01 23:57 ` Re: loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
2002-11-02 20:44 ` Re: loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
@ 2002-11-03 01:23 ` Bruce Momjian <pgman@candle.pha.pa.us>
1 sibling, 0 replies; 9+ messages in thread
From: Bruce Momjian @ 2002-11-03 01:23 UTC (permalink / raw)
To: Naomi Walker <nwalker@eldocomp.com>; +Cc: Bhuvan A <bhuvansql@myrealbox.com>; pgsql-admin
We do have /contrib/dblink in 7.3 that allows cross-db query access. We
don't have any pass-data-between-db's capability that I know of.
---------------------------------------------------------------------------
Naomi Walker wrote:
> Exactly. My Informix background is showing. Is there a way to officially
> get this put on a to do list? I'd be most appreciative of the value this adds.
>
> Slightly off subject, is there a way to read from one cluster and insert
> into a database in another cluster (local or remote)? I think I read this
> is coming in the future. In Informix-land, we used to do this through a
> named pipe. It was quite handy.
>
> At 10:39 PM 11/1/02 -0500, Bruce Momjian wrote:
>
> >Yes, agreed, it would be nice to have WHERE as part of COPY. In fact, I
> >like Informix's solution, which merges data in/out with INSERT/SELECT:
> >
> > UNLOAD TO '/tmp/x'
> > SELECT *
> > FROM tab;
> >
> >and
> >
> > LOAD FROM '/tmp/x'
> > INSERT INTO tab;
> >
> >It is tough to beat this flexibility.
> >
> >---------------------------------------------------------------------------
> >
> >Naomi Walker wrote:
> > >
> >
> > > The problem with COPY, I think, is that I cannot use a WHERE
> > > statement. I'd like to just unload certain rows from a table. If I
> > wanted
> > > the whole table, i'll do a pg_dump or copy.
> > >
> >
> > > Again, i'd like a way to easily unload some selected rows (select * table
> > > where foo=X) from a table, and save them, or load them in another cluster,
> > > etc. Short of writing them to a temp table, then pg_dumping, or some
> > > klunk-oid mething, I do not see a clean way.
> > >
> > > Back to the maddening crowd. Anyone at least agreed this is
> > needed? Could
> > > we add "where" clauses to COPY? That would be perfect.
> > >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: loading and unloading rows
2002-11-01 00:36 loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
2002-11-01 23:57 ` Re: loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
2002-11-02 20:44 ` Re: loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
@ 2002-11-03 23:41 ` Naomi Walker <nwalker@eldocomp.com>
2002-11-08 04:46 ` Re: loading and unloading rows Bruce Momjian <pgman@candle.pha.pa.us>
1 sibling, 1 reply; 9+ messages in thread
From: Naomi Walker @ 2002-11-03 23:41 UTC (permalink / raw)
To: Bruce Momjian <pgman@candle.pha.pa.us>; Naomi Walker <nwalker@eldocomp.com>; +Cc: Bhuvan A <bhuvansql@myrealbox.com>; pgsql-admin
Can we add unload/load functionality to the list, please?
> > >Yes, agreed, it would be nice to have WHERE as part of COPY. In fact, I
> > >like Informix's solution, which merges data in/out with INSERT/SELECT:
> > >
> > > UNLOAD TO '/tmp/x'
> > > SELECT *
> > > FROM tab;
> > >
> > >and
> > >
> > > LOAD FROM '/tmp/x'
> > > INSERT INTO tab;
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: loading and unloading rows
2002-11-01 00:36 loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
2002-11-01 23:57 ` Re: loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
2002-11-02 20:44 ` Re: loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
2002-11-03 23:41 ` Re: loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
@ 2002-11-08 04:46 ` Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 0 replies; 9+ messages in thread
From: Bruce Momjian @ 2002-11-08 04:46 UTC (permalink / raw)
To: Naomi Walker <nwalker@eldocomp.com>; +Cc: Bhuvan A <bhuvansql@myrealbox.com>; pgsql-admin
Naomi Walker wrote:
> Can we add unload/load functionality to the list, please?
>
>
>
> > > >Yes, agreed, it would be nice to have WHERE as part of COPY. In fact, I
> > > >like Informix's solution, which merges data in/out with INSERT/SELECT:
> > > >
> > > > UNLOAD TO '/tmp/x'
> > > > SELECT *
> > > > FROM tab;
> > > >
> > > >and
> > > >
> > > > LOAD FROM '/tmp/x'
> > > > INSERT INTO tab;
I have thought of that. We would probably join COPY to INSERT/SELECT
rather than use LOAD/UNLOAD. The problem is that the COPY code reads
right out of the table, rather than reading from the executor. This
change would require that. You can do it now by using TEMP tables to do
the COPY.
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: loading and unloading rows
@ 2002-11-05 18:50 Murthy Kambhampaty <murthy.kambhampaty@goeci.com>
0 siblings, 0 replies; 9+ messages in thread
From: Murthy Kambhampaty @ 2002-11-05 18:50 UTC (permalink / raw)
To: Bruce Momjian <pgman@candle.pha.pa.us>; Naomi Walker <nwalker@eldocomp.com>; +Cc: Bhuvan A <bhuvansql@myrealbox.com>; pgsql-admin
As long as you are going to use pipes to do your "load/unload" or "read from
one cluster, copy to another", why not go with:
/usr/local/pgsql/bin/psql -U xxxx -d xxxx -h xxxx \
-P format=unaligned -P fieldsep='\t' -P tuples_only \
-c "select * from tab where yoo='hoo'" | /usr/local/pgsql/bin/psql
-U xxxx -d xxxx -h xxxx \
-c "copy bar from stdin"
You don't have to do the text processing Bhuvan described, just obviate it
with the right options to psql. You don't need additional functionality in
postgresql unless you want to do it all with SQL rather than from a shell or
other client interface (you may have problems using named pipes from, say, a
python interface running on Windows, but you can work around that too).
Finally, you're not asking for a where clause for copying from a text file
to a pg table, are you? THAT is going to take a temporary table in any case,
it seems, so why not do it yourself?
Cheers,
Murthy
-----Original Message-----
From: Bruce Momjian [mailto:pgman@candle.pha.pa.us]
Sent: Saturday, November 02, 2002 20:24
To: Naomi Walker
Cc: Bhuvan A; pgsql-admin@postgresql.org
Subject: Re: [ADMIN] loading and unloading rows
We do have /contrib/dblink in 7.3 that allows cross-db query access. We
don't have any pass-data-between-db's capability that I know of.
---------------------------------------------------------------------------
Naomi Walker wrote:
> Exactly. My Informix background is showing. Is there a way to officially
> get this put on a to do list? I'd be most appreciative of the value this
adds.
>
> Slightly off subject, is there a way to read from one cluster and insert
> into a database in another cluster (local or remote)? I think I read this
> is coming in the future. In Informix-land, we used to do this through a
> named pipe. It was quite handy.
>
> At 10:39 PM 11/1/02 -0500, Bruce Momjian wrote:
>
> >Yes, agreed, it would be nice to have WHERE as part of COPY. In fact, I
> >like Informix's solution, which merges data in/out with INSERT/SELECT:
> >
> > UNLOAD TO '/tmp/x'
> > SELECT *
> > FROM tab;
> >
> >and
> >
> > LOAD FROM '/tmp/x'
> > INSERT INTO tab;
> >
> >It is tough to beat this flexibility.
> >
>
>---------------------------------------------------------------------------
> >
> >Naomi Walker wrote:
> > >
> >
> > > The problem with COPY, I think, is that I cannot use a WHERE
> > > statement. I'd like to just unload certain rows from a table. If I
> > wanted
> > > the whole table, i'll do a pg_dump or copy.
> > >
> >
> > > Again, i'd like a way to easily unload some selected rows (select *
table
> > > where foo=X) from a table, and save them, or load them in another
cluster,
> > > etc. Short of writing them to a temp table, then pg_dumping, or some
> > > klunk-oid mething, I do not see a clean way.
> > >
> > > Back to the maddening crowd. Anyone at least agreed this is
> > needed? Could
> > > we add "where" clauses to COPY? That would be perfect.
> > >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2002-11-08 04:46 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-11-01 00:36 loading and unloading rows Naomi Walker <nwalker@eldocomp.com>
2002-11-01 09:22 ` Bhuvan A <bhuvansql@myrealbox.com>
2002-11-01 23:57 ` Naomi Walker <nwalker@eldocomp.com>
2002-11-02 03:39 ` Bruce Momjian <pgman@candle.pha.pa.us>
2002-11-02 20:44 ` Naomi Walker <nwalker@eldocomp.com>
2002-11-03 01:23 ` Bruce Momjian <pgman@candle.pha.pa.us>
2002-11-03 23:41 ` Naomi Walker <nwalker@eldocomp.com>
2002-11-08 04:46 ` Bruce Momjian <pgman@candle.pha.pa.us>
2002-11-05 18:50 Re: loading and unloading rows Murthy Kambhampaty <murthy.kambhampaty@goeci.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