def psql_query(query, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None):
 ret = []
 csv_query = 'COPY ({0}) TO STDOUT WITH CSV HEADER'.format(query.strip().rstrip(';'))
 cmdret = _psql_prepare_and_run(['-v', 'datestyle=ISO,MDY', '-c', csv_query], runas=runas, host=host, user=user, port=port, maintenance_db=maintenance_db, password=password)
 if (cmdret['retcode'] > 0):
  return ret
 csv_file = StringIO(cmdret['stdout'])
 header = {}
 for row in csv.reader(csv_file, delimiter=',', quotechar='"'):
  if (not row):
   continue
  if (not header):
   header = row
   continue
  ret.append(dict(zip(header, row)))
 return ret

def psql_query ( query , user = None , host = None , port = None , maintenance_db = None , password = None , runas = None ) : ret = [ ] csv_query = 'COPY ({0}) TO STDOUT WITH CSV HEADER' . format ( query . strip ( ) . rstrip ( ';' ) ) cmdret = _psql_prepare_and_run ( [ '-v' , 'datestyle=ISO,MDY' , '-c' , csv_query ] , runas = runas , host = host , user = user , port = port , maintenance_db = maintenance_db , password = password ) if ( cmdret [ 'retcode' ] > 0 ) : return ret csv_file = StringIO ( cmdret [ 'stdout' ] ) header = { } for row in csv . reader ( csv_file , delimiter = ',' , quotechar = '"' ) : if ( not row ) : continue if ( not header ) : header = row continue ret . append ( dict ( zip ( header , row ) ) ) return ret
run an sql-query and return the results as a list .