Tuesday, November 22, 2016

Custom PG Range: where to place register_range() call?

I was following the documentation at https://docs.djangoproject.com/en/1.10/ref/contrib/postgres/fields/#defining-your-own-range-types in order to create a custom range.

It says that I have to use the function register_range() from psycopg2. I suppose that the code should be something like this:
from psycopg2.extras import register_range
TimeRangeCaster = register_range('timerange', 'TimeRange', conn_or_curs=???, globally=???)
TimeRange = TimeRangeCaster.range


Suppose that previously I had executed this on postgresql
CREATE FUNCTION time_subtype_diff(x time, y time) RETURNS float8 AS
'SELECT EXTRACT(EPOCH FROM (x - y))' LANGUAGE sql STRICT IMMUTABLE;

CREATE TYPE timerange AS RANGE
(
    subtype
= time,
    subtype_diff
= time_subtype_diff
);


1) Is register_range() supposed to go in app.py, AppConfig, models.py or where?
2) In order to integrate this in a django app. Should I use the argument globally=True for register_range()? Should I pass a connection or cursor for the argument conn_or_curs?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bd9565f5-5244-4215-8e0a-f6a3f944dc34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment