Re: [SQL] cast bool/int

2009-03-24 Thread Jasen Betts
On 2009-03-23, Zdravko Balorda  wrote:
>
> Hi,
> I need a casting operator from boolean to integer,

  you can use any expression

> tu put in ALTER TABLE statment after USING.
>
> Any ideas? Thanks.

 CASE WHEN columname THEN 1 WHEN NOT columname THEN 0 ELSE NULL END


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] cast bool/int

2009-03-23 Thread Zdravko Balorda



CASE WHEN column='t' THEN 1 ELSE 0 END


Or just CASE WHEN column THEN 1 ELSE 0 END.


In the mean time I've got an elegant solution:

alter ... ... column TYPE smallint USING column::boolean::int::smallint;

It works, you wouldn't beleive it. ;)
Zdravko

--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] cast bool/int

2009-03-23 Thread Marcin Krawczyk
This:

SELECT true::integer, false::integer

also works on 8.1

--
regards
mk

2009/3/23 Achilleas Mantzios 

> Στις Monday 23 March 2009 09:59:12 ο/η Zdravko Balorda έγραψε:
> >
> > Hi,
> > I need a casting operator from boolean to integer,
> > tu put in ALTER TABLE statment after USING.
> >
>
> Sorry in the above email i meant smth like
> CASE WHEN column='t' THEN 1 ELSE 0 END
>
> however
> SELECT 't'::boolean::int;
> int4
> --
>1
> (1 row)
>
> and
> SELECT 'f'::boolean::int;
>  int4
> --
>0
> (1 row)
>
> work in 8.3
>
> > Any ideas? Thanks.
> >
> > Zdravko
> >
> >
>
>
>
> --
> Achilleas Mantzios
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>


Re: [SQL] cast bool/int

2009-03-23 Thread Joshua Tolley
On Mon, Mar 23, 2009 at 10:18:31AM +0200, Achilleas Mantzios wrote:
> Στις Monday 23 March 2009 09:59:12 ο/η Zdravko Balorda έγραψε:
> > 
> > Hi,
> > I need a casting operator from boolean to integer,
> > tu put in ALTER TABLE statment after USING.
> > 
> 
> Sorry in the above email i meant smth like
> CASE WHEN column='t' THEN 1 ELSE 0 END

Or just CASE WHEN column THEN 1 ELSE 0 END.

- Josh / eggyknap


signature.asc
Description: Digital signature


Re: [SQL] cast bool/int

2009-03-23 Thread Achilleas Mantzios
Στις Monday 23 March 2009 09:59:12 ο/η Zdravko Balorda έγραψε:
> 
> Hi,
> I need a casting operator from boolean to integer,
> tu put in ALTER TABLE statment after USING.
> 

Sorry in the above email i meant smth like
CASE WHEN column='t' THEN 1 ELSE 0 END

however 
SELECT 't'::boolean::int;
int4
--
1
(1 row)

and 
SELECT 'f'::boolean::int;
 int4
--
0
(1 row)

work in 8.3

> Any ideas? Thanks.
> 
> Zdravko
> 
> 



-- 
Achilleas Mantzios

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] cast bool/int

2009-03-23 Thread Achilleas Mantzios
Στις Monday 23 March 2009 09:59:12 ο/η Zdravko Balorda έγραψε:
> 
> Hi,
> I need a casting operator from boolean to integer,
> tu put in ALTER TABLE statment after USING.
> 

How about
CASE WHEN 't' THEN 1 ELSE 0 END

> Any ideas? Thanks.
> 
> Zdravko
> 
> 



-- 
Achilleas Mantzios

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


[SQL] cast bool/int

2009-03-23 Thread Zdravko Balorda


Hi,
I need a casting operator from boolean to integer,
tu put in ALTER TABLE statment after USING.

Any ideas? Thanks.

Zdravko


--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql