Re: get date in binary number format

From: "Johnson, Shaunn" <SJohnson6(at)bcbsm(dot)com>
To: 'Alvaro Herrera' <alvherre(at)atentus(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: get date in binary number format
Date: 2002-09-26 15:55:59
Message-ID: 73309C2FDD95D11192E60008C7B1D5BB04C73FBE@snt452.corp.bcbsm.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

--thanks for the reply:

--this is how the algorithm was explained to me (except
--when i tried the select date part of the sql below, i
--got an error (ERROR: Bad date external representation '1'):

[snip]

Algorithm to select backup number:
smallest non-zero place in binary representation of the backup number
(which in the example is complicated somewhat by the fact we back up
only on weekdays).

e.g.

if the first backup is 2002-01-01 (tuesday) the backup for 8/21/02 would be
(('2002-08-21'::date-2002-01-01'::date-extract('dow' from
'2001-01-01'::datetime))/7)::int4*5
+(extract('dow' from '2002-08-21'::datetime)::int4%6)
which gives us backup #168
168 as binary is 10101000. The "smallest nonzero digit" is the "1" in
the 8's place. numbering the backups as:

8 7 6 5 4 3 2 1 <- backup set ("tape") #
1 0 1 0 1 0 0 0 <- binary of backup #

using "9-length(rtrim( --previous-result-- , '0'))", we would use backup
set ("tape") # 4

we will always have 1, 2 and no more than 4-day old backups.
going to a depth of 8 "sets" us a max history of between 25 and 50
weeks. 10 "sets" goes back 2 to 4 years, and no tape drive will need to
be purchased, or maintained, and no tapes can be lost.

[/snip]

--not sure if anyone else has heard of this
--but it was a new one to me ... hope that at least
--explains some of what i'm trying to do.

--thanks again!

-X

-----Original Message-----
From: Alvaro Herrera [mailto:alvherre(at)atentus(dot)com]
Sent: Thursday, September 26, 2002 11:50 AM
To: Johnson, Shaunn
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] get date in binary number format

Johnson, Shaunn dijo:

> Howdy:
>
> Silly question time -
>
> Is there a way to get the date and change
> it into a binary number?

Well, you can get the day of the year in binary:

testing=> select "bit"((date_part('doy', now()))::integer);
bit
----------------------------------
00000000000000000000000100001101
(1 row)

> The algorithm to select backup number would be the
> smallest non-zero place in binary representation of
> the backup number (tape).

Recursive definition? Sorry, I don't understand the algorithm.

--
Alvaro Herrera (<alvherre[a]atentus.com>)
"Ni aun el genio muy grande llegaria muy lejos
si tuviera que sacarlo todo de su propio interior" (Goethe)

Browse pgsql-general by date

  From Date Subject
Next Message Grgory Luguet 2002-09-26 16:07:49 can Trigger be as real "standalone" program?
Previous Message mourad_dhambri 2002-09-26 15:52:34 dblink