[AOLSERVER] ns_db exec retrieve stdout (postgresql copy to)

9 views
Skip to first unread message

Matt Haggard

unread,
Jun 9, 2009, 11:49:11 AM6/9/09
to AOLS...@listserv.aol.com
PostgreSQL has a COPY TO command ( http://www.postgresql.org/docs/8.1/static/sql-copy.html
), which outputs query results in CSV format.

It would be neat if I could execute the command using ns_db dml rather
than parsing in TCL. COPY TO writes the result to STDOUT (or a file,
but I'd like to not use a file). Any help?

I've been going through the ns_db source, but I dead-end at
NsDbGetDriver();

Thanks,

Matt Haggard


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <list...@listserv.aol.com> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of your email blank.

Tom Jackson

unread,
Jun 9, 2009, 2:43:19 PM6/9/09
to AOLS...@listserv.aol.com
Matt,

This is probably a mistake. The COPY command creates a text file (or CLOB), which _must_ be parsed if you want to create records and fields.

Just use dml to get the data into an ns_set, or the C API equivalent. All CSV handlers have problems. PostgreSQL's COPY seems to have difficulty with quoting, meaning the quote character might appear unescaped in a field, causing errors. ns_csv* has problems with record boundaries: each record must be on one line, so \n, etc. don't pass through.

In general, it is a bad idea to convert your data to a more ambiguous format and then try to recover it unchanged. That is why we have ns_set, arrays and lists. I work with pg's COPY because it is fast, extremely fast, but your data must be perfect to use it.

You could try using COPY to a file then see how fast ns_csvget is, but I assume that the regular database API will be faster, and over time, using a database API will be much less prone to errors. If this isn't important, you might reconsider using a database in the first place.

tom jackson
Reply all
Reply to author
Forward
0 new messages