Quantcast
Channel: Planet PostgreSQL
Viewing all articles
Browse latest Browse all 9659

Andrew Dunstan: row_to_csv

$
0
0
You can get rows as CSV lines by using the COPY command. This works well, but there are times when it's not convenient. For example, one of my clients uses software where the driver doesn't support COPY mode, unfortunately. We could add support for libpq's COPY functions to the driver, but that would involve quite a bit of work. Another possibility occurred to me, namely that it would be easy to produce rows as CSV via a function. This took only a few hours to produce the other day, based on my earlier work turning rows into json. It's not quite ready for prime time yet, but I wonder if this has more general use than my client's particular case. Here's an example:
andrew=# select row_to_csv(q) 
         from (select relname, relfilenode, relacl 
               from pg_class 
               limit 1) q ;
                 row_to_csv                 
--------------------------------------------
 pg_statistic,12540,{andrew=arwdDxt/andrew}+
 
(1 row)
The idea is to allow options to the functions similar to COPY's delimiter, null_string, quote and escape options, and possibly force quote as well. That part isn't done yet :-)

Viewing all articles
Browse latest Browse all 9659

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>