Column as alias is ambigous in Postgresql
<p>I am migrating the database from MySQL to Postgrsql. In MySQL I create a view like this:</p>

<pre><code> create or replace view translated_attributes_with_attribute_templatevalues as
select
concat_ws('',
    translated_attributevalues.attribute_id,
    translated_attributevalues.languagecode,
    attribute_template_value.id
) AS id,
    ...
    GROUP BY id
</code></pre>

<p>But in Postgrsql I got the message:</p>

<p>column reference "id" is ambiguous
LINE 1: ...GROUP BY id</p>

<p>How can I use the alias "id"?</p>

<p>I renamed it, but than other parts of the code break, because it assumes the column is named id.</p>

<p>Either repeat the expression in the <code>GROUP BY</code> clause:</p>

<pre><code>GROUP BY concat_ws('', ...)
</code></pre>

<p>or use the result column number:</p>

<pre><code>GROUP BY 1
</code></pre>

<p>The only advantage of the first solution is that it complies with the SQL standard.</p>

python django postgresql