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 13th, 2012, 04:20 AM
apocalys apocalys is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 3 apocalys User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 5 sec
Reputation Power: 0
Some problem during conversion from MySql to PosgreSql

Hi all,

I need to convert this mysql script into posgresql script but any time I give some error. Can anyone help me?

Code:
SELECT  
		DL1.`refId_user` AS `search_refId_user`, 
		DL2.`refId_user`, 
		U.`name`, U.`surname`, 
		D.`desc` AS `discussion_desc`, 
		D.`id` AS `refId_discussion`
FROM 	
		(SELECT * FROM `DISTRIBUTION_LIST` WHERE `refId_user` = 121 GROUP BY `refId_discussion` ORDER BY `id` DESC LIMIT 10) DL1,
		`DISTRIBUTION_LIST` DL2,
		`USERS` U,
		`DISCUSSIONS` D
WHERE
		DL1.`refId_discussion` = DL2.`refId_discussion` AND
		DL2.`refId_user` = U.`id` AND
		DL2.`refId_discussion` = D.`id`
ORDER BY 
		D.`id` DESC, 
		DL2.`id` DESC;


tkx to all!

Reply With Quote
  #2  
Old June 13th, 2012, 05:59 AM
shammat shammat is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Oct 2003
Location: Germany
Posts: 2,684 shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 3 Days 19 h 37 m 6 sec
Reputation Power: 284
Remove those invalid backticks. That's not valid SQL

Depending on how you created the tables and columns you will probably need to replace them with double quotes:

so

DL1.`refId_user` AS `search_refId_user`,

has to be

DL1."refId_user" AS "search_refId_user",


The next time please also post the error message.

Reply With Quote
  #3  
Old June 13th, 2012, 07:13 AM
apocalys apocalys is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 3 apocalys User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 5 sec
Reputation Power: 0
I correct all backticks:

Code:
SELECT  
		"DL1"."refId_user" AS "search_refId_user", 
		"DL2"."refId_user", 
		"U"."name", "U"."surname", 
		"D"."desc" AS "discussion_desc", 
		"D"."id" AS "refId_discussion"
FROM 	
		(SELECT * FROM "DISTRIBUTION_LIST" WHERE "refId_user" = 121 GROUP BY "refId_discussion" ORDER BY "id" DESC LIMIT 10) "DL1",
		"DISTRIBUTION_LIST" "DL2",
		"USERS" "U",
		"DISCUSSIONS" "D"
WHERE
		"DL1"."refId_discussion" = "DL2"."refId_discussion" AND
		"DL2"."refId_user" = "U"."id" AND
		"DL2"."refId_discussion" = "D"."id"
ORDER BY 
		"D"."id" DESC, 
		"DL2"."id" DESC;


I get the following error:
Code:
ERROR:  column "DISTRIBUTION_LIST.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 8:   (SELECT * FROM "DISTRIBUTION_LIST" WHERE "refId_user" = 12...


If I correct the script in this way
PHP Code:
 SELECT  
        
"DL1"."refId_user" AS "search_refId_user"
        
"DL2"."refId_user"
        
"U"."name""U"."surname"
        
"D"."desc" AS "discussion_desc"
        
"D"."id" AS "refId_discussion"
FROM     
        
(SELECT FROM "DISTRIBUTION_LIST" WHERE "refId_user" 121 GROUP BY "refId_discussion""id" ORDER BY "id" DESC LIMIT 10"DL1",
        
"DISTRIBUTION_LIST" "DL2",
        
"USERS" "U",
        
"DISCUSSIONS" "D"
WHERE
        
"DL1"."refId_discussion" "DL2"."refId_discussion" AND
        
"DL2"."refId_user" "U"."id" AND
        
"DL2"."refId_discussion" "D"."id"
ORDER BY 
        
"D"."id" DESC
        
"DL2"."id" DESC

it is correct and work but the result that i get is not correct cause that the group by for "refId_discussion" is not working.

How i can fix the script?

Tkx to all

Reply With Quote
  #4  
Old June 13th, 2012, 07:26 AM
shammat shammat is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Oct 2003
Location: Germany
Posts: 2,684 shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 3 Days 19 h 37 m 6 sec
Reputation Power: 284
All columns that are not used in an aggregate column must appear in the group by clause (as the error message says). MySQL incorrect behaviour returned some arbitrary (read random) rows from the group when not following that rule.

But as you are not using any aggregates in your statement, the group by does not make any sense anyway. What is it you are trying to achieve?

Reply With Quote
  #5  
Old June 13th, 2012, 08:15 AM
apocalys apocalys is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 3 apocalys User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 5 sec
Reputation Power: 0
I have to extract data from this schema:

Table Discussion (id)
Table Messages (id)
Table Distribution_list (id, discussionId, messageId, userId)
Table User (id)

User1 send a message, that belongs to a discussion, to User2:
system add into Distribution_list this 2 row ({discussionId, messageId, user1}, {discussionId, messageId, user2}).

I need to get all user's discussion, with all participant.

I hope to had explain well my situation.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Some problem during conversion from MySql to PosgreSql

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