This is a Postgres extension for a bunch of general-purpose functions I find useful, especially around time zones, but some other stuff too.
This package installs like any Postgres extension. First say:
make && sudo make install
You will need to have pg_config
in your path,
but normally that is already the case.
You can check with which pg_config
.
Then in the database of your choice say:
CREATE EXTENSION pjpg;
Once you've installed the extension, you can use these functions:
Converts "blank" strings to NULL
,
where blank is any string that is empty or contains nothing but whitespace.
It is the same meaning as the blank?
method in Rails
or the ActiveRecord presence
validation,
when used on strings.
This function is intended to use in triggers to keep null-like data out of not-null columns.
Converts t
from the timezone from_tz
to the timezone to_z
.
The *_tz
parameters should be strings that match entries in pg_catalog.pg_timezone_names.name
,
e.g. America/Los_Angeles
.
This method does not change the instant of t
,
but tells you the same instant in a different place.
It is useful as an input to date_trunc
,
so that you can slice the timeline into days using the right timezone.
Like the 3-arg version, but assumes t
is in UTC.
Given a time t
and its timezone tz
, finds the first moment of the day.
Given a time t
and its timezone tz
, finds the first moment of the week.
This function follows USA conventions, where the week begins on Sunday.
(This is different than the built-in date_trunc('week', ...)
function.)
Given a time t
and its timezone tz
, finds the first moment of the week.
This function follows ISO conventions, where the week begins on Monday.
(This is the same as than the built-in date_trunc('week', ...)
function,
except this function uses the specified time zone.)
Alias for beginning_of_week_usa
.
Returns a [)
range spanning width
days and beginning at midnight
on the same day as time t
in timezone tz
.
Returns a [)
range spanning width
weeks and beginning at midnight Sunday
on the same week as time t
in timezone tz
.
Returns a [)
range spanning width
weeks and beginning at midnight Monday
on the same week as time t
in timezone tz
.
Alias for weekusa_range
.