Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I can't seem to translate from SQL to postgresql correctly when using SELECT, why is this wrong?

My code works fine in a SQL database but when trying to execute on postgresql, it starts throwing an error. I’ve tried adding "symbol" after GROUP BY and even "symbol.symbol"

SELECT symbol,name,price,total, SUM(shares) 
FROM symbol 
WHERE user_id=? 
GROUP BY name

column "symbol.symbol" must appear in the GROUP BY clause or be used in an aggregate function

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Every field that is not part of a domain (or aggregate) function in the select list needs to be in the group-by clause. In your case, that’s symbol, name, price, and total.

Furthermore, name and total are terrible field names, as they are reserved words. In SQL Server, you would enclose those in square brackets. In PostgreSQL you would put them in double-quotes.

But really, you should not use those names.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading