How can I write the following MySQL query in PostgreSQL syntax:
SELECT CONCAT(REPEAT(" ", (COUNT(parent.name) - 1)), cat.name) AS name
Thanks in advance!
How can I write the following MySQL query in PostgreSQL syntax:
SELECT CONCAT(REPEAT(" ", (COUNT(parent.name) - 1)), cat.name) AS name
Thanks in advance!
The error here is that PostgreSQL doesn't allow double quotes
"for literal strings (as per the SQL standard). You'll need to use single quotes'.You also need to cast
(COUNT(parent.name) - 1)to an integer, either using::int(specific to Postgre) orCAST(... AS int).Note that this may raise an
integer out of rangeerror if(COUNT(parent.name) - 1)is superior to 2147483647.Note that you can also use
||for string concatenation :