Skip to content

Commit

Permalink
Update README, add LICENSE
Browse files Browse the repository at this point in the history
  • Loading branch information
codeinthehole committed Nov 29, 2012
1 parent 6f5ab1a commit 8d40ae3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 32 deletions.
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (C) 2012 foie gras authors

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# Foie Gras

+------------------+
| __ |
| uh oh >(' ) |
| __ | FOIE GRAS
| uh oh >(' ) | The missing CSV loading library for Postgres
| )/ |
| /( |
| / `----/ |
| \ ~=- / |
| ~^~^~^~^~^~^~^~^ |
+----------------- +

## The missing CSV loading library for Postgres

In MySQL you can do this:

mysql> LOAD DATA INFILE '/tmp/data.csv'
Expand All @@ -32,29 +29,32 @@ This is not possible in Postgres...

Yay!

## Interesting... tell me more.
## Interesting... tell me more

The Postgres equivalent of [`LOAD DATA INFILE`](http://dev.mysql.com/doc/refman/5.1/en/load-data.html)
is the [`COPY ... FROM ...`](http://www.postgresql.org/docs/9.2/static/sql-copy.html) command,
however it does not support replacing rows that match on a unique constraint.
The Postgres equivalent of [`LOAD DATA INFILE`](http://dev.mysql.com/doc/refman/5.1/en/load-data.html)
is the [`COPY ... FROM ...`](http://www.postgresql.org/docs/9.2/static/sql-copy.html)
command, however it does not support replacing rows that match on a unique
constraint. Using CSVs to load data into a table is the fastest way of
updating a table - hence it's frustrating that Postgres doesn't
support the `REPLACE` option that MySQL does.

This works around this lack of functionality by loading the CSV to a temporary table then
This package works around this issue by loading the CSV to a temporary table then
updating the master table using two `UPDATE` commmands that insert new records and update
matching records respectively.
matching records respectively. All very simple.

Further reading:

* [Relevant Stack Overflow question](http://stackoverflow.com/questions/8910494/how-to-update-selected-rows-with-values-from-a-csv-file-in-postgres)
* [Wiki page for COPY](http://www.postgresql.org/docs/9.2/static/sql-copy.html)
* [Populating a database](http://www.postgresql.org/docs/8.3/static/populate.html)

## Surely this has been done already?

Apparently not. There are some similar ones though:

http://pypi.python.org/pypi/django-csvimport
* custom file field that looks at header and matches against other model fields

http://djangosnippets.org/snippets/633/
Apparently not. There are some similar CSV loading libraries for Django

pgloader - http://pgfoundry.org/projects/pgloader/
* [`django-csvimport`](http://pypi.python.org/pypi/django-csvimport) - This is a Django
app for uploading CSV files to populate model tables. It uses the ORM directly to save
new instances and so does not perform well when loading larges volumes of data.

* [pgloader](http://pgfoundry.org/projects/pgloader/) - This looks like it might be quite good
but it's hard to tell as the docs are so bad. It's also not on PyPI.
4 changes: 4 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* Django support
* HEADER option
* CSV file
* Match COPY options
14 changes: 0 additions & 14 deletions notes.rst

This file was deleted.

0 comments on commit 8d40ae3

Please sign in to comment.