return true / false instead of int4 value

Started by Johnson, Shaunnalmost 24 years ago5 messagesgeneral
Jump to latest
#1Johnson, Shaunn
SJohnson6@bcbsm.com

Howdy:

I want to know if this is even possible: How
can I return a true/false value instead of
integer?

I want to do something like this:

[snip]

select count(*) from t_table
having count(*) > 1500000

[/snip]

But want to return a true/false (bool) result.

Background:

The goal is to do what I have been doing for the
past few weeks - get a count of a table and,
based on the count, either create a new table
or fail and halt the rest of the related process.

I've done the function thing - it doesn't work
very well. It stalls a few times and somehow
I created a bogus function type in one of the
system tables ... so ... I'm going to stay
away from that.

I've created a perl script to do exactly what
I want! ... 'cept ... during the regular
database refresh, it doesn't complete
until well AFTER I need it to ... other views
and tables are dependent on this one being
created first.

SO ... I'm looking for a nitch on how to
convert (and cast won't work for me) the
type from 'int4' to 'bool' for the above
sql excerpt.

*whew*

Suggestion?

HEY: Somebody send me some disco ... er ...
motivation music!

-X

#2Peter Darley
pdarley@kinesis-cem.com
In reply to: Johnson, Shaunn (#1)
Re: return true / false instead of int4 value

return true / false instead of int4 valueShaunn,
You can do something like:
SELECT CASE WHEN COUNT(*) > 1500000 THEN TRUE ELSE FALSE END FROM
t_table WHERE Whatever GROUP BY Whatever;
Thanks,
Peter Darley
-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org]On Behalf Of Johnson, Shaunn
Sent: Tuesday, June 04, 2002 9:00 AM
To: pgsql-general@postgresql.org
Subject: [GENERAL] return true / false instead of int4 value

Howdy:

I want to know if this is even possible: How
can I return a true/false value instead of
integer?

I want to do something like this:

[snip]

select count(*) from t_table
having count(*) > 1500000

[/snip]

But want to return a true/false (bool) result.

Background:

The goal is to do what I have been doing for the
past few weeks - get a count of a table and,
based on the count, either create a new table
or fail and halt the rest of the related process.

I've done the function thing - it doesn't work
very well. It stalls a few times and somehow
I created a bogus function type in one of the
system tables ... so ... I'm going to stay
away from that.

I've created a perl script to do exactly what
I want! ... 'cept ... during the regular
database refresh, it doesn't complete
until well AFTER I need it to ... other views
and tables are dependent on this one being
created first.

SO ... I'm looking for a nitch on how to
convert (and cast won't work for me) the
type from 'int4' to 'bool' for the above
sql excerpt.

*whew*

Suggestion?

HEY: Somebody send me some disco ... er ...
motivation music!

-X

#3Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Johnson, Shaunn (#1)
Re: return true / false instead of int4 value

On Tue, 4 Jun 2002, Johnson, Shaunn wrote:

Howdy:

I want to know if this is even possible: How
can I return a true/false value instead of
integer?

I want to do something like this:

[snip]

select count(*) from t_table
having count(*) > 1500000

[/snip]

But want to return a true/false (bool) result.

Wouldn't select count(*)>1500000 from t_table;

give you a true/false based on whether the count
is greater than that number?

#4Doug Fields
dfields-pg-general@pexicom.com
In reply to: Johnson, Shaunn (#1)
Re: return true / false instead of int4 value

select count(*) from t_table
having count(*) > 1500000

[/snip]

But want to return a true/false (bool) result.

Off the top of my head:

select count > 1500000 from (select count(*) as count from t_table) as a;

Doug

#5Johnson, Shaunn
SJohnson6@bcbsm.com
In reply to: Doug Fields (#4)
Re: return true / false instead of int4 value

--Thanks all (esp. doug, peter, stephan)

--works like a charm!

-X

-----Original Message-----
From: Stephan Szabo [mailto:sszabo@megazone23.bigpanda.com]

On Tue, 4 Jun 2002, Johnson, Shaunn wrote:

Howdy:

I want to know if this is even possible: How
can I return a true/false value instead of
integer?

I want to do something like this:

[snip]

select count(*) from t_table
having count(*) > 1500000

[/snip]

But want to return a true/false (bool) result.

Wouldn't select count(*)>1500000 from t_table;

give you a true/false based on whether the count
is greater than that number?