473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

Nov 23 '05 #1
2 3232
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:
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 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #2
On Fri, 2 Apr 2004 18:21:34 -0500, Randall Skelton
<sk*****@brutus.uwaterloo.ca> wrote:
UPDATE app_id_800 SET cal_byte_w_err = (CASE WHEN
cal_byte_w_err.value=1 THEN 't'::boolean ELSE 'f'::boolean END)


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

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jakob Bieling | last post by:
Hi, I have a question about casting and using the casted pointer: Suppose I have a 'base' class and a 'derived' class (which is derived from 'base'). Now I have this scenario: base* p1 = new...
3
by: Steve Teeples | last post by:
I have a method that passes in two string objects (both numerical numbers) and a string identifying their type. public bool DoCompare(string num1, string num2, string theirType) { System.Type...
3
by: Dariusz Tomon | last post by:
Hi I'm trying to retrieve data from database (MS Sql serv) from field of BIT type. I'm trying like this: while (myReader.Read()) { Int16 cos = (Int16)myReader.GetSqlInt16(1);
8
by: scroopy | last post by:
hi, why does the following produce an output of 64769 instead of 1 int main() { bool* pBool = new bool(false); unsigned short* pUS = (unsigned short*)pBool;
5
by: anders.forsgren | last post by:
This is a common problem with generics, but I hope someone has found the best way of solving it. I have these classes: "Fruit" which is a baseclass, and "Apple" which is derived. Further I have...
2
by: Giulio Petrucci | last post by:
Hi everybody, here's my problem: I have to dymanically build (and compile, of course) some code, from some ECMAScript function. ECMAScript variables I get are not typezed, so I should have...
1
by: Jay Hamilton | last post by:
Hello, I am running into an invalid address alignment error on an HPUX box when I attempt to lookup a value in a STL map. The argument being passed in is a double, which is accessed from a...
3
by: Trev | last post by:
Hi, I have a series of functions which do the following: ValidateData( args ); //args if of type ArrayList // Work out if the data is valid or not, and work out the type of args - int, string,...
8
by: mfc | last post by:
Suppose I have a Cookie class and a Factory Class. There are many types of Cookies and maybe one or more Factories with a ProcessCookie Method. Suppose all the PutInBox method does is decide what...
2
by: =?Utf-8?B?R2Vvc3Ns?= | last post by:
Dear All, I try to change a master page in the OnPreInit in a asp.net page. (Session variable is guaranteed to have been assigned) protected override void OnPreInit(EventArgs e){ if...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.