PostgreSQL Syntax error in PGAdmin

亡梦爱人 提交于 2019-12-05 05:22:13

You can use the do statement. For example:

do $$
declare 
  num integer := 10;
begin

    RAISE INFO 'VARIABLE: %', num;

end;
$$language plpgsql;

When you use pgadmin you have to use the button EXECUTE QUERY instead of Execute pdScript, as it is explained here:

http://postgresql.1045698.n5.nabble.com/PgAmin3-Anonymous-code-block-can-t-be-executed-by-pressing-quot-Execute-PG-script-quot-button-td5771073.html

The documentation for do statements is here:

http://www.postgresql.org/docs/9.3/static/sql-do.html

Just to rephrase and "concretize" what others say: There are no inline procedures in PostgreSQL. There is also no PRINT statement. You have to:

CREATE OR REPLACE FUNCTION test() RETURNS void AS $$
DECLARE
  num INTEGER;

BEGIN

  num := 3;
  RAISE NOTICE '%', num;

END;
$$ LANGUAGE plpgsql;

SELECT test();

If you're trying to print out num (say, for debugging), you could try:

RAISE NOTICE '%', num;

http://www.postgresql.org/docs/8.4/static/plpgsql-errors-and-messages.html

PRINT doesn't mean anything in PL/pgSQL.

I have no idea what you are trying to achieve. PostgreSQL doesn't support this kind of syntax. Similar keywords (except PRINT?!) are in PL/pgSQL which is procedural language for building FUNCTIONS, not for writing stand-alone SQL queries.

Postgres doesn't support anything like that by itself (yet). psql (the official command line client) has some rudimentary scripting.

The best option for you is pgAdmin which already has scripting built-in.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!