Re: Non-aggregate values attached to aggregates?

Поиск
Список
Период
Сортировка
От Benjamin Smith
Тема Re: Non-aggregate values attached to aggregates?
Дата
Msg-id 200412161521.35985.lists@benjamindsmith.com
обсуждение исходный текст
Ответ на Re: Non-aggregate values attached to aggregates?  (Michael Fuhr <mike@fuhr.org>)
Ответы Re: Non-aggregate values attached to aggregates?
Список pgsql-general
Thanks much for your help!

It took a few tries to get what it was all about, but I got it.

On Thursday 16 December 2004 14:09, Michael Fuhr wrote:
> > Dates are kept as ]YYYYMMDD', eg 2004114 for Nov 14, 2004.
>
> Why not use a DATE type?  You can reformat it with to_char() if
> need be.

Not a bad idea. I used int because it was simple and "good enough". My app is
written in PHP, and by using strtotime() I can trap typo errors before they
get near the database (which frequently are difficult to display in a
layperson readable format)

EG:

$sql="INSERT INTO enrollments (date) values ('[date]')";
$pass=array('date'=>$_ENROLL['date'];
if (!$DB->SafeQuery($sql, $pass))
 return error("Database Error: ".$DB->Error());

If there's an error here, it'd say something like: "ERROR: Bad date external
representation 'mya 11 2004'. Compare with:

$sql="INSERT INTO enrollments (date) VALUES [date]";
IF (($date=strtotime($_REQUEST['date'])) ==-1)
    return Error("I'm sorry, but ".$_REQUEST['date']." does not appear to be a
valid date. Please fix and try again");
if (!$DB->SafeQuery($sql, array('date'=>$date)))
    return error("Database Error: ".$DB->Error());

which is much more "friendly" to the end user.

BTW: What is to_char, and why doesn't this work in PG 7.3.x?

select to_char(datefield) from TableX;

-Ben
--
"The best way to predict the future is to invent it."
- XEROX PARC slogan, circa 1978


В списке pgsql-general по дате отправления:

Предыдущее
От: Michael Fuhr
Дата:
Сообщение: Re: MD5
Следующее
От: Tino Wildenhain
Дата:
Сообщение: Re: MD5