Re: [GENERAL] Another one! :) How to convert char(1) to boolean without re-exporting tables.

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: Valerio Santinelli <tanis(at)mediacom(dot)it>
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] Another one! :) How to convert char(1) to boolean without re-exporting tables.
Date: 1999-01-19 15:40:43
Message-ID: l03110700b2ca56ffa369@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter T Mount 1999-01-19 21:08:51 Re: [GENERAL] Graphics Supported?
Previous Message Valerio Santinelli 1999-01-19 14:58:16 Another one! :) How to convert char(1) to boolean without re-exporting tables.