Re: plpython3
От | James William Pye |
---|---|
Тема | Re: plpython3 |
Дата | |
Msg-id | DC4B46E2-4643-4558-800C-2466F7CB34B3@jwp.name обсуждение исходный текст |
Ответ на | Re: plpython3 (Greg Smith <greg@2ndquadrant.com>) |
Ответы |
Re: plpython3
Re: plpython3 Re: plpython3 |
Список | pgsql-hackers |
On Jan 14, 2010, at 7:08 PM, Greg Smith wrote: > So more targeted examples like you're considering now would help. Here's the trigger example which should help reveal some of the advantages of "native typing". This is a generic triggerthat constructs and logs manipulation statements for simple replication purposes. The original plpython version is located here: http://ar.pycon.org/common/2009/talkdata/PyCon2009/020/plpython.txt [You'll need to scroll down to the very bottom of that page.] There are three points in this example that need to be highlighted: 1. There is no need for a "mogrify" function (see original in the above link). 2. Attributes/columns of the records (new/old) are extracted when referenced. 3. The comparisons in after_update uses the data type's actual inequality operator. The first point is true because "native typing" gives the user direct access to a given type's typoutput via ``str(ob)``.This makes constructing the PG string representation of a given object *much* easier--quote_nullable, and done.The original plpython example will need to be updated to compensate for any changes in conversion: arrays will now needspecial handling and MD arrays will not work at all. It also relies heavily on the Python object representation matchingPG's; where that fails, special cases need to be implemented(composites, notably). All of that compensation performedin the original version is unnecessary in the plpython3 version. The second point touches on the "efficiency" that was referenced in an earlier message. No cycles are spent converting thecontents of a container object unless the user chooses to. Naturally, there is no advantage performance-wise if you arealways converting everything. I'd wager that with triggers, it's rare that everything needs to be converted. The third point reveals that Postgres.Object instances--a component of native typing--use the data type's operator for inequality.It's not limited to comparisons as all available Python operators are mapped to corresponding operators in PG.For many or all primitives, there is no added value over conversion. However, this provides a lot of convenience whenworking with UDTs, datetime types, and geometric types. ...ISTM that the primary advantage of "native typing" is that we get to define the Python interface to a given Postgres datatype. Three files are attached: afterlog.py - the trigger returning function afterlog.sql - the sql exercising the TRF (creates the replica_log table as well) afterlog.out - the contents of the replica_log table after executing afterlog.sql To replay: \i afterlog.py \i afterlog.sql SELECT * FROM replica_log;
Вложения
В списке pgsql-hackers по дате отправления: