M
M
Maxim Tarabrin2018-02-01 12:01:51
PostgreSQL
Maxim Tarabrin, 2018-02-01 12:01:51

What causes the POSTGRESQL procedure to fail?

my procedure

CREATE OR REPLACE FUNCTION auto_increment_version(id bigint)
  RETURNS bigint
LANGUAGE plpgsql
AS $$
DECLARE
  res BIGINT;
BEGIN
  SELECT COUNT(*)
  INTO res
  FROM appsellschema."product-version"
  WHERE template_id = id;
  RETURN res+1;
END;
$$;

SELECT appsellschema.auto_increment_version(1);
To console error
[2018-02-01 12:50:40] [42702] ERROR: column reference "id" is ambiguous
[2018-02-01 12:50:40] Details: It could refer to either a PL/pgSQL variable or a table column.
[2018-02-01 12:50:40] Where: PL/pgSQL function appsellschema.auto_increment_version(bigint) line 6 at SQL statement
[2018-02-01 12:50:40] Summary: 1 of 1 statements executed, 1 failed in 33ms (46 symbols in file)
Where to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2018-02-01
@padr1no

The reason for the storage error is fully and reliably indicated in the details of the error text:
You have an id field in the table, the id argument for the storage - which of them is implied by the parser does not understand.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question