Search code examples
postgresqlcoalesce

inner query in coalesce to set null values


I am new in postgres and I would like to set null fields to some other values. When I run this query, it works fine:

SELECT COALESCE(Field,'xxx) from Table;

However, instead of having 'xxx' for all those fields, I want to fill them like this:

SELECT COALESCE(Field,select id from user where user.id = someOtherTable.id) from Table; 

In this one, I am getting a syntax error near select.

How can I dynamically set these values?


Solution

  • As @Abelisto said in the comment, parantheses around the inner query worked