Dear Curtis,

> might be 0 vs 1, T vs F, or Y vs N, or any combination of these.
> Is there a MySQL logical field type that will handle any/all of these at
> one time?

AFAIK you can accomplish this only on the application side. In MySQL, you
can work with ENUM('0','1')) or even CHAR(0) NOT NULL (which will store just
1 byte, either NULL or ''), but MySQL has no conversion like 'n' -> '0'.

Another thing you can do is:

mysql> SELECT CASE 'your_value_from_the_application'
    ->  WHEN 'T' THEN 1
    ->  WHEN 'Y' THEN 1
    ->  WHEN '1' THEN 1
    ->  WHEN 'TRUE' THEN 1
    ->  ELSE 0
    -> END;

As everything is case-insensitive, this will also catch "t", "y", "true",
"tRuE", etc. And it's fast as hell, like everything in MySQL :)

Hope it helps,
--
  Stefan Hinz <[EMAIL PROTECTED]>
  CEO / Geschäftsleitung iConnect GmbH <http://iConnect.de>
  Heesestr. 6, 12169 Berlin (Germany)
  Telefon: +49 30 7970948-0  Fax: +49 30 7970948-3


----- Original Message -----
From: "Lorenzo Curtis" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, December 02, 2002 9:19 PM
Subject: Logical Field Type


> I am working with data that the field values coming into the database
> might be 0 vs 1, T vs F, or Y vs N, or any combination of these.
>
> Is there a MySQL logical field type that will handle any/all of these at
> one time?
>
>
> Example:
> I would like the following data
> +-------+-------+-------+-------+
> | Fld1  | Fld2  | Fld3  | Log   |
> +-------+-------+-------+-------+
> | rec1a | rec1b | rec1c | Y     |
> | rec2a | rec2b | rec2c | N     |
> | rec3a | rec3b | rec3c | T     |
> | rec4a | rec4b | rec4c | F     |
> | rec5a | rec5b | rec5c | 0     |
> | rec6a | rec6b | rec6c | 1     |
> | rec7a | rec7b | rec7c | False |
> | rec8a | rec8b | rec8c | True  |
> +-------+-------+-------+-------+
>
> to be stored into a database as:
> +-------+-------+-------+-----+
> | Fld1  | Fld2  | Fld3  | Log |
> +-------+-------+-------+-----+
> | rec1a | rec1b | rec1c | 1   |
> | rec2a | rec2b | rec2c | 0   |
> | rec3a | rec3b | rec3c | 1   |
> | rec4a | rec4b | rec4c | 0   |
> | rec5a | rec5b | rec5c | 0   |
> | rec6a | rec6b | rec6c | 1   |
> | rec7a | rec7b | rec7c | 0   |
> | rec8a | rec8b | rec8c | 1   |
> +-------+-------+-------+-----+
>
>
> -------------------------------------
> Lorenzo Curtis
> Dead River Company
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
<[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to