Suggestions for moving from SQLIte to PostgreSQL ?
This is more appropriate for stack-overflow, as the issue tracker is used for tracking issues with the library.

I'm currently using SQLite as the backend for a simulation program and am interested in supporting the use of PostgreSQL to allow for multiple independent simulations to be run in parallel.

The blocker is a user-defined function.

SQLite has no SQL functions so I wrote it in python

PostgreSQL might be able to use PL/python - but its unclear how to integrate that with peewee.

I suppose I could have two implementations (python, SQL), but that would be less than optimal (and how do I get configuration data into a SQL function - plus one reason I wrote it in python was that I couldn't get my head around it in SQL). 

The function is doing set math and returning a bool that is used in the parent query.


What have other people done in tis area ?

```
    allowed = False

    try:

        relatives_1 = set()
        relatives_2 = set()

        # TODO - make the "relationship limit" configurable
        common_ancestor = censere.models.RelationshipEnum.great_great_great_grandparent

        for r1 in censere.models.Relationship.select(censere.models.Relationship.second).where( 
                ( censere.models.Relationship.first == id_1 ) &
                ( censere.models.Relationship.relationship <= common_ancestor ) 
            ).tuples():
            relatives_1.add( str(r1[0]) )

        for r2 in censere.models.Relationship.select(censere.models.Relationship.second).where( 
                ( censere.models.Relationship.first == id_2 ) &
                ( censere.models.Relationship.relationship <= common_ancestor ) 
            ).tuples():
            relatives_2.add( str(r2[0]) )

        if relatives_1 == relatives_2:
            allowed = False

        if len(relatives_1 & relatives_2) == 0:
            allowed = True

    except Exception as e:

        logging.log( logging.ERROR, 'Caught exception %s', str(e) )

    return allowed


```


