Skip to main content

Database query code returning numpy arrays

Project description

Build Status Documentation Status


Python module to query SQL databases and return numpy arrays, upload tables and run join queries involving local arrays and the tables in the DB. The module only works for PostgreSQL and sqlite databases.

The full documentation is available here


To install the package you just need to do pip install.

pip install sqlutilpy

Querying the database and retrieving the results

ra,dec = sqlutil.get('select ra,dec from mytable', host='HOST_NAME_OF_MY_PG_SERVER', db='THE_NAME_OF_MY_DB')

By default sqlutil.get executes the result and returns the tuple of results

Uploading your arrays as column in a table

x = np.arange(10)                                                   
y = x**.5                                                           

This will create a table called mytable with columns xcol and ycol

Join query involving your local data and the database table

Imagine you have arrays myid and y and you want to to extract all the information from somebigtable for objects with id=myid. In principle you could upload the arrays in the DB and run a query, but local_join function does that for you.

myid = np.arange(10)
y = x**.5
sqlutilpy.local_join('select * from mytmptable as m, somebigtable as s where order by m.myid',                                                                           'mytmptable',(x,y),('myid','ycol'))

It executes a query as if you arrays where in a mytmptable. ( behind the scenes it uploads the data to the db and runs a query)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for sqlutilpy, version 0.13.0
Filename, size File type Python version Upload date Hashes
Filename, size sqlutilpy-0.13.0.tar.gz (13.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page