|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
You can do date and time arithmetic using current time functions or a timestamp column in your table. For example to add or subtract seven days try: select datefield + 7 from table where id=1; select now() + '7 days'::interval; select now() - '7 days'::interval;Be sure to look at the documentation under the Functions and Operators Chapter in the PostgreSQL Users Guide: Date/Time Functions and Operators. There you can also find variations like the date_part() function.
Here are some recommendations for documentation on PHP and PostgreSQL. Book
Oracle has a way of "pinning" a table into memory for faster access. PostgreSQL does not because general concensus is that it is not a good idea. If the table is accessed enough, it will be in the cache anyway. If it is not, then perhaps it wasn't the best candidate for the cache and it would have the effect of making the problem worse. Pinning a table would be "just mucking with the symptoms instead of curing the [disease]". However, it is acknowledged that the caching algorithms for PostgreSQL are due for tune-up and there are people looking at the issues now.
There is no particular setting in PostgreSQL for a connection timeout. However, for TCP connections PostgreSQL enables TCP KEEPALIVE. Tom Lane says, "If network connectivity to the client is lost the kernel will time out and close the connection. The length of the keepalive timeout is kernel-dependent but should be an hour or more in RFC-compliant implementations."
To count the rows resulting in a selection use: select count(*) from (select ....) foo; or select count(*) from ....; But don't forget that count(*) is not a speedy function. If you must have the count and are fetching the rows for further processing, it is suggested that you count the results in the client.
Storing timestamps with timezones lets the database handle the timezone conversions. When you select or run a report, the data will be in the current timezone. To run a report for someone in a different timezone, you can set the timezone in SQL before running the report. You can "change" timezones to affect the output of the report or query in order to generate more meaningful reports for people in different timezones.
area=# select current_time; timetz -------------------- 10:03:02.390849-06 (1 row) area=# set time zone 'PST8PDT'; SET area=# select current_time; timetz -------------------- 08:03:19.241939-08 PostgreSQL stores time in UTC like Unix. The timezone determines the display formatting. Each "reader" of the data will see the time in their own timezone. You also use timezones when you want to preserve the original timezone of the data. You must know or store separately the origin timezone and apply it with set time zone 'xxx'. For example, sometimes it makes more sense to be clear that something happened at commute time in Minneapolis than to know it happened early afternoon in California.
|
||||||||||||||||||||||||||||||
Comments and Corrections are welcome. Suggestions and contributions of items are also welcome. Send them in! Copyright A. Elein Mustain 2003, 2004, 2005, 2006, 2007, 2008, 2009 |