postgresql/src/backend
Bruce Momjian 46be0c18f1 > After all that about numbering centuries and millenia correctly,
> why does CVS tip still give me
>
> regression=# select extract(century from now());
>  date_part
> -----------
>         20
> (1 row)
> [ ... looks in code ... ]
>
> Apparently it's because you fixed only timestamp_part, and not
> timestamptz_part.  I'm not too sure about what timestamp_trunc or
> timestamptz_trunc should do, but they may be wrong as well.

Sigh... as usual, what is not tested does not work:-(


> Could we have a more complete patch?

Please find a submission attached. I hope it really fixes all decade,
century and millenium issues for extract and *_trunc functions on
interval
and other timestamp types. If someone could check that the results
are reasonnable, it would be great.

I indeed overlooked the fact that there were two functions. The patch
fixes the code so that both variants agree.

I added comments to interval extractions, because it relies on the C
division to have a negative remainder: -7/10 = 0 and remains -7.

As for *_trunc functions, I have chosen to put the first year of the
century or millennium: -100, 1, 101... 1001 2001 etc. Indeed, I don't
think it would make sense to put 2000 (last year of the 2nd millennium)
for rounding all years of the third millenium.

I also fixed the code so that all decades last 10 years and decade 199
means the 1990's.

I have added some tests that are relevant to deal with tricky cases. The
formula may be simplified, but all these cases must pass. Please keep
them.

Fabien Coelho
2004-08-20 03:45:14 +00:00
..
access Fix bug introduced into _bt_getstackbuf() on 2003-Feb-21: the initial 2004-08-17 23:15:33 +00:00
bootstrap For EXEC_BACKEND case, BootstrapMain needs to recompute paths, same as 2004-07-31 17:57:11 +00:00
catalog Repair some issues with column aliases and RowExpr construction in the 2004-08-19 20:57:41 +00:00
commands Dept. of further reflection: I looked around to see if any other callers 2004-08-15 23:44:46 +00:00
executor Standardize on the assumption that the arguments of a RowExpr correspond 2004-08-17 18:47:09 +00:00
lib Add tests to enlargeStringInfo() to avoid possible buffer-overrun or 2004-05-11 20:07:26 +00:00
libpq Specify SA_NOCLDSTOP when enabling SIGCHLD, per suggestion from 2004-08-15 05:25:10 +00:00
main Replace direct fprintf(stderr) calls by write_stderr(), and cause this 2004-06-24 21:03:42 +00:00
nodes Label CVS tip as 8.0devel instead of 7.5devel. Adjust various comments 2004-08-04 21:34:35 +00:00
optimizer Repair some issues with column aliases and RowExpr construction in the 2004-08-19 20:57:41 +00:00
parser Repair some issues with column aliases and RowExpr construction in the 2004-08-19 20:57:41 +00:00
po Translation updates 2004-08-14 19:16:07 +00:00
port Replace direct fprintf(stderr) calls by write_stderr(), and cause this 2004-06-24 21:03:42 +00:00
postmaster Cleanup Win32 COPY handling, and move archive examples to SGML. 2004-08-12 19:03:44 +00:00
regex Solve the 'Turkish problem' with undesirable locale behavior for case 2004-05-07 00:24:59 +00:00
rewrite Repair some issues with column aliases and RowExpr construction in the 2004-08-19 20:57:41 +00:00
storage Dept. of further reflection: I looked around to see if any other callers 2004-08-15 23:44:46 +00:00
tcop Allow commas in BEGIN, START TRANSACTION, and SET TRANSACTION, as required 2004-08-12 21:00:34 +00:00
utils > After all that about numbering centuries and millenia correctly, 2004-08-20 03:45:14 +00:00
Makefile Add libpgport to postgres.def for Windows build. Per Magnus Hagander. 2004-08-01 18:07:42 +00:00
nls.mk Add translation from 7.4 branch to head. 2004-08-11 09:00:27 +00:00