Yehor Androsov
Yehor Androsov

Reputation: 6152

Incorrect syntax near 'PROCEDURE' postgresql

My database is hosted in Amazon and I am using pgAdmin 4 to connect to it. I copy-pasted snippet from https://www.postgresql.org/docs/11/sql-createprocedure.html

CREATE PROCEDURE insert_data(a integer, b integer)
LANGUAGE SQL
AS $$
   INSERT INTO tbl VALUES (a);
   INSERT INTO tbl VALUES (b);
$$;

The issue is that I get 'incorrect syntax near 'PROCEDURE' ' error enter image description here

What is done wrong? Not sure how I check version of postgresql itself

Upvotes: 0

Views: 2558

Answers (2)

user330315
user330315

Reputation:

With Postgres 10, you need to use a function:

CREATE function insert_data(a integer, b integer)
  returns void
LANGUAGE SQL
AS $$
   INSERT INTO tbl VALUES (a), (b);
$$;

Upvotes: 4

Yasen
Yasen

Reputation: 4476

According to PostgreSQL documentation, syntax is supported in versions 11 and 12.

PostgreSQL: Documentation: 11: CREATE PROCEDURE

DocumentationPostgreSQL 11

Supported Versions: Current (11)

Development Versions: 12 / devel

Check PostgreSQL version on your server, run this query from PgAdmin:

SELECT version();

Upvotes: 1

Related Questions