Обсуждение: Another one! :) How to convert char(1) to boolean without re-exporting tables.
Another one! :) How to convert char(1) to boolean without re-exporting tables.
От
Valerio Santinelli
Дата:
Ok. This time it's a bit more difficult ;) I'd like to convert my char(1) stuff to boolean without having to kill the table and re-export the original from MSAccess. I think there's a way to do that since just creating a new table with bool instead of char(1) won't let me insert into it the values contained in the old table seeing they're not of the same type. Thanks as always!! :) Valerio Santinelli tanis@mediacom.it
At 16:58 +0200 on 19/1/99, Valerio Santinelli wrote: > char(1) won't let me insert into it the values contained in the old > table seeing they're not of the same type. Why not? It all depends on how you populate the new table. You do that usually with a SELECT statement. A select statement like SELECT field_1, field_2, ( char_field = '1' ), field 4, field5... gives you a boolean expression - is the char_field equal to '1' at the current row? Some versions of Postgres crash when given a boolean expression on the select target list. In that case you can define it as a function CREATE FUNCTION is_one( bpchar ) RETURNS bool AS 'SELECT $1 = ''1''' LANGUAGUE 'sql'; And then do the select as SELECT field_1, field_2, is_one( char_field), field4, field5.... Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma