OK, I have spent some time on my postgres wrapper, using Haukes comment I now have this:
NB. Simple crude SELECT operation pgsel=: 3 : 0 conn=: pqconnectdb<'dbname=usda' res=: pqexec conn;'select * from fd_group order by fddrp_desc limit 3' ncols=: pqnfields res nrows=: pqntuples res ) NB. From Hauke on the mailing list NB. pqfname@(res&;)"0 i. ncols columns =: 3 : 'dtb each<"1 psz@pqfname@(y&;)"0 i.ncols' row =: 3 : 0 'res row'=.y psz @ pqgetvalue @ (res;row & ;) "0 i. pqnfields res ) rowb =: 3 : 'psz @ pqgetvalue @ (y & ;) "0 i. pqnfields y' rows=: 3 : 0 rows=. dtb each <"1 row @ (y & ;)"0 i. pqntuples y (columns y),rows ) When run I get this output, good, but I have some points I seek clarification on, here is the output: load'psql.ijs' pgsel'' 3 rows res ┌────────┬──────────────┐ │fdgrp_cd│fddrp_desc │ ├────────┼──────────────┤ │0300 │Baby Foods │ ├────────┼──────────────┤ │1800 │Baked Products│ ├────────┼──────────────┤ │1300 │Beef Products │ └────────┴──────────────┘ *Foggy bit 1: * I had to use 'dtb' to remove the trailing blanks from the column names, but annoyingly they were only added after the 'psz' step, for clarity, the implementation, *Foggy bit 2:* At some point in 'row' I realised I was extracting 'res' and 'row' from 'y' and then immediately boxing them back up again! So I naively assumed that rowb would work but it gives me a domain error: |domain error: pqnfields | psz@pqgetvalue@(y&;)"0 i. pqnfields y this is psz: NB. Prints NUL terminated C string given starting y address psz=: 3 : 'memr (>y),0,_1' and PQnfields > i x I am just not sure why I am getting the domain error. Thanks again. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
