Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old November 23rd, 2005, 12:26 AM
Randall Skelton
Guest
 
Posts: n/a
Default Casting int to bool with join...

I am trying to update rows in a new table and re-cast to boolean at the
same time. I am absolutely certain that the integers are 0 or 1. Is
there a one line way to do this?

UPDATE app_id_800 SET cal_byte_w_err = cal_byte_w_err.value::boolean
FROM cal_byte_w_err
WHERE app_id_800.timestamp BETWEEN '2004-01-01 00:00:00' AND
'2004-01-01 00:00:05'
AND app_id_800.timestamp = cal_byte_w_err.timestamp;

Many thanks... I've spent way too long trying to figure this out :(

Cheers,
Randall


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

  #2  
Old November 23rd, 2005, 12:26 AM
Randall Skelton
Guest
 
Posts: n/a
Default Re: Casting int to bool with join...

Got it.

UPDATE app_id_800 SET cal_byte_w_err = (CASE WHEN
cal_byte_w_err.value=1 THEN 't'::boolean ELSE 'f'::boolean END)
FROM cal_byte_w_err
WHERE app_id_800.timestamp BETWEEN '2004-01-01 00:00:00' AND
'2004-01-01 00:00:05'
AND app_id_800.timestamp = cal_byte_w_err.timestamp;

Have a good weekend all.
Randall

On 2 Apr 2004, at 18:05, Randall Skelton wrote:
[color=blue]
> I am trying to update rows in a new table and re-cast to boolean at
> the same time. I am absolutely certain that the integers are 0 or 1.
> Is there a one line way to do this?
>
> UPDATE app_id_800 SET cal_byte_w_err = cal_byte_w_err.value::boolean
> FROM cal_byte_w_err
> WHERE app_id_800.timestamp BETWEEN '2004-01-01 00:00:00' AND
> '2004-01-01 00:00:05'
> AND app_id_800.timestamp = cal_byte_w_err.timestamp;
>
> Many thanks... I've spent way too long trying to figure this out :(
>
> Cheers,
> Randall[/color]


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

  #3  
Old November 23rd, 2005, 12:26 AM
Manfred Koizar
Guest
 
Posts: n/a
Default Re: Casting int to bool with join...

On Fri, 2 Apr 2004 18:21:34 -0500, Randall Skelton
<skelton@brutus.uwaterloo.ca> wrote:[color=blue]
>UPDATE app_id_800 SET cal_byte_w_err = (CASE WHEN
>cal_byte_w_err.value=1 THEN 't'::boolean ELSE 'f'::boolean END)[/color]

or simply

UPDATE app_id_800
SET cal_byte_w_err = (cal_byte_w_err.value=1)

Servus
Manfred

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles