PostgreSQL a LC_TIME
Karel Zak
zakkr na zf.jcu.cz
Čtvrtek Duben 7 12:54:28 CEST 2005
On Wed, 2005-04-06 at 09:19 +0200, Otakar Kleps wrote:
> Karel Zak wrote:
> > Protoze to nemusi byt snadne. DB potrebuje pro svuj beh nejake presne
> > definovane locales v kterych ma indexy. Prepinani mezi ruznymi locales
> > podle potreb (ruzne indexy, ruzne formatovane vystupy apod.) je neco co
> > neni implementovane (protoze to vubec neni trivialni). Ono myslet si, ze
> > zavolam setlocale() milionkrat za jeden SQL dotaz je proste blby
> > napad... :-)
>
> Trosku z jineho soudku - v tom pripade me zajima, proc to co oznacujes
> za "blby napad" ma v sobe postgres pravdepodobne implemnentovano prave
> pri praci s casem. Neni totiz jedno, kdyz napisu podminku
> _date=CURRENT_DATE a nebo _date='2005-04-06'::date(kde _date je typ date).
Jinak u "blbeho napadu" jsem mluvil o setlocale() a ne time() coz bych
videl jako rozdil :-)
>
> Obecne dle 'explain analyze' je vyhodnejsi pouzit prave ten druhy zpusob
> zapisu. Me totiz prijde, ze pri vyhodnoceni podminky dotazu si PG pro
> kazdy vyhodnocovany zaznam generuje aktualni CURRENT_DATE a ten pak
> pouzije. Proc tomu tak je?
Ne. CURRENT_ neci a 'now' pouzivaji cas transakce a vraci po dobu
transakce stale stejny cas. Pro aktualni cas si saha jen timeofday().
http://www.postgresql.org/docs/8.0/static/functions-
datetime.html#FUNCTIONS-DATETIME-CURRENT
It is important to know that CURRENT_TIMESTAMP and related functions
return the start time of the current transaction; their values do not
change during the transaction. This is considered a feature: the intent
is to allow a single transaction to have a consistent notion of the
"current" time, so that multiple modifications within the same
transaction bear the same time stamp. timeofday() returns the wall-clock
time and does advance during transactions.
Karel
--
Karel Zak <zakkr na zf.jcu.cz>
Další informace o konferenci Test