Error 42702 Column Reference Is Ambiguous PostgreSQL

IT Support Forum Forums Databases PostgreSQL SQL Queries Error 42702 Column Reference Is Ambiguous PostgreSQL

Viewing 0 reply threads
  • Author
    Posts
    • #2291
      Webmaster
      Keymaster

      PostgreSQL displays error 42702 with message:

      Column reference is ambiguous

      when you reference a column without referencing the table it came from, in cases where a column reference could have come from one or more tables.

      To fix this, specify the table name prior to the column reference.

      For example, the below query might state that the column reference is ambigious because ID might be in the dogList and catList table:

      SELECT id, cats, dogs
      FROM dogList
      JOIN catList
      ON dogList.id = catList.column_name;

      Remove the ambiguity by referencing the table that contains the ID; example below:

      SELECT dogList.id, cats, dogs
      FROM dogList
      JOIN catList
      ON dogList.id = catList.column_name;

Viewing 0 reply threads
  • You must be logged in to reply to this topic.