Skip to main content

Database query code returning numpy arrays

Project description

Build Status Documentation Status

sqlutilpy

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

Installation

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                                                           
sqlutil.upload('mytable',(x,y),('xcol','ycol'))    

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 s.id=m.myid 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.

Source Distribution

sqlutilpy-0.0.7.tar.gz (7.5 kB view details)

Uploaded Source

File details

Details for the file sqlutilpy-0.0.7.tar.gz.

File metadata

  • Download URL: sqlutilpy-0.0.7.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.5.2

File hashes

Hashes for sqlutilpy-0.0.7.tar.gz
Algorithm Hash digest
SHA256 b43d24c341baa6994f273996041077f314a0fec8f3c863119329dd7be3472cec
MD5 e4d3582f8d6ad76ec71a9a8594b7e2f2
BLAKE2b-256 5d1d2f4b289e59c9fa0085684a6de1d28fb0233a7c3b9412d4e549485deb97c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page