PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 9th, 2003, 02:53 AM
wanaka wanaka is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 40 wanaka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 7 sec
Reputation Power: 11
Sum IF Support by postgres

I want to do similar query like the one mention in devshed article by using postgres instead of mysql.

This is the article location.
http://www.devshed.com/Server_Side/...LWiz/page3.html

But I keep getting this error message.
Error: ERROR: Function if(boolean, integer, integer) does not exist
Unable to identify a function that satisfies the given argument types
You may need to add explicit typecasts

I have no idea what this error mean.

Reply With Quote
  #2  
Old June 9th, 2003, 03:25 PM
bcyde's Avatar
bcyde bcyde is offline
Me likey breadsticks...
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2003
Location: Los Angeles
Posts: 1,189 bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 1 h 12 m 58 sec
Reputation Power: 17
Send a message via AIM to bcyde Send a message via Yahoo to bcyde
Ok, I guess there's a few things to address:

1)The error message. The error message is saying that Postgres does not recognize the IF function you are trying to use, meaning that there is no IF function, or the paramaters that you are passing to the IF function are of the wrong type and may need casting to the correct types. Off the top of my head I don't know if Postgres has an exact corollary to that MySQL IF function, perhaps one of the mods or more experienced PG developers can answer that.

2)How can you get the same type of resulting output from Postgres ?
You can probably do (basing my db structure off of the link you gave in here
Try something like this (note untested query as I don't have a DB like this lying around):

SELECT location, SUM(CASE gender='M' THEN 1 ELSE 0 END) AS M, SUM(CASE gender='F' THEN 1 ELSE 0 END) AS F FROM locations, employees WHERE locations.loc_code = employees.loc_code GROUP BY location;

HTH helps,
-b
__________________
PostgreSQL, it's what's for dinner...

Reply With Quote
  #3  
Old June 9th, 2003, 09:48 PM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Central Florida, USA
Posts: 2,306 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 6 h 42 m 51 sec
Reputation Power: 60
Yes, there is no IF function in PostgreSQL that works the way MySQL's IF function works. But, in PostgreSQL, you can do all that and more with the CASE and COALESCE expressions. In fact, COALESCE works very similarly to the MySQL IF function (although more logically, IMHO), while CASE allows for true multi-line control structures, similar to if-else constructs.

If you want more control structure functionality, you can always write a stored procedure in PL/PgSQL.
__________________
The real n-tier system:

FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

Amazon wishlist -- rycamor (at) gmail.com

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Sum IF Support by postgres

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap