On 10/17/2014 08:04 PM, Michael Bayer wrote:
>
>> This is what I get in SQLAlchemy
>>
>>
>> {'calculateTaxesByID': {('totalPriceEx()',): {}}, 'averageCost': {None:
>> Decimal('7.4838709677419355')}, 'totalPriceEx': {None: Decimal('17.50')},
>> 'getBasePriceEx': {None: Decimal('17.50')}}
>>
>> This is the result when I rand the following code in Postgresql
>>
>> "{'calculateTaxesByID': {('totalPriceEx()',): {}}}”
>
> I’ve no experience running Python under postgresql directly but it looks very
> much like the pickling in PG is not working correctly, as it is omitting a
> lot of data. The use of Decimal objects is the only thing that stands out
> as something that could change, if you’ve upgraded from very old psycopg2
> versions to recent ones. I can’t see how this has much to do with
> SQLAlchemy directly however, obviously those extra keys are present in the
> data.
>
> I’d debug this by looking at the data directly and sending it to a local
> loads() function, comparing that to what this stored procedure is returning.
Yes, it's essential to determine that the raw byte string being decoded
is the one you expect.
>>
>> My question for sqlalchmy or is this psycopg2 question?
>
> it’s a Python pickle format question, or a “how does Python run under
> Postgresql question”, from what I can see.
Python runs under PostgreSQL like it does most places else since it's a
regular CPython interpreter embedded in Postgres. Anything in the
standard library, such as pickling and unpickling, uses the ordinary
CPython implementation.
OTOH, accessing the database requires using a library with a
significantly different interface from the likes of psycopg2. Marc
didn't give any detail about how he's retrieving values from the table
within his Python stored procedure. It's possible there's something
interesting going on there vs. how psycopg2 is retrieving values.
>
>>
>> is there any data manipulation that is happened before the pickle.loads
>> function gets called? so is there any processing happening before
>>
>> def result_processor(self, value, dialect):
>
> not really, but in any case, definitely work on getting round trips with
> psycopg2 directly at the very least.
>
>
>>
>> I put a break point in the debugger and looked on the stack but didn't see
>> anything getting done to the data at first quickly looking now.
>>
>> Which i could get some inside in this?
>
> running Python in a PG stored procedure is a very advanced and esoteric
> scenario, so if you are going there you need to be prepared to debug this
> down to the byte level yourself :).
You could say that writing PostgreSQL functions in a procedural language
is an advanced topic. However, writing them in Python isn't very
esoteric as Python is a fully supported and documented high level
server-side language along with pgSQL, TCL and Perl:
<URL:http://www.postgresql.org/docs/9.2/static/plpython.html>
Extending Python's pickle protocol is a lot more esoteric IMHO and I'm
very curious about why that is necessary.
--
Jonathan Rogers
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.