function [data] = pg_query(conn, numeric, statement, varargin) % Performs query on database initiated with conn % % [data] = pg_query(conn, numeric, statement, varargin) % data: return data % conn: conn object from pg_connect % numeric: return data are numeric if set to 1, otherwise cell % statement: SQL statement formatted for sprintf % varargin: variable number of arguments for the SQL statement % var = []; if ( length(varargin) > 0 ) stat = sprintf(statement, varargin{:}); else stat = statement; end % stat if numeric > 0 setdbprefs('DataReturnFormat','numeric'); else setdbprefs('DataReturnFormat','cellarray'); end curs = exec(conn, stat); curs_data = fetch(curs); data = curs_data.Data;