agora inbox for postgres@postgres.berkeley.edu
help / color / mirror / Atom feedUtility for tab_separated_text
2+ messages / 2 participants
[nested] [flat]
* Utility for tab_separated_text
@ 1995-02-12 00:56 Pconrad@eecis.udel.edu
0 siblings, 1 reply; 2+ messages in thread
From: Pconrad@eecis.udel.edu @ 1995-02-12 00:56 UTC (permalink / raw)
To: legacy; +Cc: pconrad@eecis.udel.edu
Hi all,
I am working on a project where I will have a need for a utility
that will take an arbitrary Postquel query and return the result as
tab separated text, suitable for importing into (for example) a
spreadsheet.
I know that the "Copy" command will copy an entire class into
a tab separated file. However, the relations I will be working with
may grow quite large, and so it would be much more convenient to not
have to edit down the rows and columns of a complete dump.
Before I go about writing such a thing:
1) Does anybody already have such a beast written?
2) Or, failing that code scraps (beyond the examples in the
std. postgres distribution) that might be helpful?
3) Or, failing that, just helpful advice for a neophyte in working with
postgres, attempting his first libpq programming project?
Thanks for your help
--Phill Conrad pconrad@cis.udel.edu
--Ph. D. Student -- Dept. of Computer and Info. Science -- Univ. of Delaware
(PS: A related utility, or perhaps a command switch? would be to write
out the results of a query to a LaTeX {tabular} environment, with column
headings=the attribute names.)
==============================================================================
To add/remove yourself to/from the POSTGRES mailing list: send mail with
the subject line ADD or DEL to "postgres-request@postgres.Berkeley.EDU".
If this fails, send mail to "post_questions@postgres.Berkeley.EDU" and
a human will deal with it. DO NOT post to the "postgres" mailing list.
==============================================================================
URL: http://s2k-ftp.CS.Berkeley.EDU:8000/postgres/
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Utility for tab_separated_text
@ 1995-02-13 20:18 Robert.Patrick@cs.cmu.edu
parent: Pconrad@eecis.udel.edu
0 siblings, 0 replies; 2+ messages in thread
From: Robert.Patrick@cs.cmu.edu @ 1995-02-13 20:18 UTC (permalink / raw)
To: legacy; Pconrad@eecis.udel.EDU; +Cc: pconrad@eecis.udel.EDU
Excerpts from internet.postgres: 12-Feb-95 Utility for
tab_separated_text Pconrad@eecis.udel.edu (1682)
> I am working on a project where I will have a need for a utility
> that will take an arbitrary Postquel query and return the result as
> tab separated text, suitable for importing into (for example) a
> spreadsheet.
Here's a somewhat crude example (please note that I am not being very
rigorous about error checking).
#include <tmp/libpq.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
int i, j, ncols, nrows;
char *dbname, query[256];
char *retval, *pstring;
PortalBuffer *pbuf;
dbname = argv[0];
sprintf(query, "retrieve (EMP.all) where EMP.name = \"bob\");
PQsetdb(dbname);
pstring= PQexec(query);
pbuf = PQparray(&(pstring[1]));
ncols = PQnfieldsGroup(pbuf, 0);
nrows = PQntuplesGroup(pbuf, 0);
/* Put the code for opening the file here */
for (i = 0; i < nrows; i++) {
char tmpbuf[4096];
int idx;
idx = 0;
for (j = 0; j < ncols; j++) {
retval = PQgetvalue(pbuf, i, j);
sprintf (&(tmpbuf[idx]), "%s\t", retval);
idx += strlen(retval) + 1;
}
tmpbuf[idx-1] = '\n'; /* overwriting final tab */
/* Put code for writing tmpbuf to the file */
}
/* Close the file */
PQfinish();
return(0);
}
I may have overlooked something but you should get the general idea of
how to do it.
Robert
==============================================================================
To add/remove yourself to/from the POSTGRES mailing list: send mail with
the subject line ADD or DEL to "postgres-request@postgres.Berkeley.EDU".
If this fails, send mail to "post_questions@postgres.Berkeley.EDU" and
a human will deal with it. DO NOT post to the "postgres" mailing list.
==============================================================================
URL: http://s2k-ftp.CS.Berkeley.EDU:8000/postgres/
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~1995-02-13 20:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1995-02-12 00:56 Utility for tab_separated_text Pconrad@eecis.udel.edu
1995-02-13 20:18 ` Robert.Patrick@cs.cmu.edu
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox