4

Part of the MySQL query that I'm trying to convert to pgSQL :

LEFT JOIN {$_TABLES['comments']} c ON c.sid = concat('fileid_' ,a.lid )

This got messy since it's concatenating a string with a column(a.lid), which isn't supported by the SQL 92 || operator(important!). Any idea's how to redo this part of the query for pgSQL?

1
  • 1
    I don't know where you get the idea that || operator cannot concatenate string with column. If this would be true it would make the operator pretty much useless. Commented Aug 13, 2009 at 10:01

2 Answers 2

5

PostgreSQL 8.3 and up supports || operator as long as at least one of the operands is a string. Concatentation of column with string literal works as well. What version are you using?

Sign up to request clarification or add additional context in comments.

3 Comments

Yea I was trying it on an older version.
According to the manual, the || string concatenation operator is supported on older versions too, such as version 7.4 (the earliest version with online docs).
You can always cast the integer one, as in: 'file_id' || CAST (a.lid AS text)
1

Please note that if you concatenate a null to anything else, all you'll get is null.

1 Comment

Correct. Not sure if that's pertinent to this question though.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.