PGAdmin中的PostgreSQL语法错误

编程入门 行业动态 更新时间:2024-10-25 20:30:06
本文介绍了PGAdmin中的PostgreSQL语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是PostgreSQL的新手,正在使用PGAdmin中的查询工具.我正在尝试运行使用变量的pgsql查询,但是似乎语法不正确.

I am new to PostgreSQL and am using the query tool in PGAdmin. I'm trying to run pgsql queries that use variables, but I can't seem to get the syntax right.

这是一个提供语法错误的示例查询:

Here's a sample query that gives a syntax error:

DECLARE num INTEGER; BEGIN num := 3; PRINT num; END;

更新: 好的,让我尝试解释一下.我来自SQL Server背景.在管理工作室中,我可以打开查询窗口并处理(T)-SQL查询.

Update: Ok, let me try and explain. I come from a SQL server background. In the management studio, I can open a query window and play with (T)-SQL queries.

例如,我可以这样写:

DECLARE @num INT SET @num = 3 SELECT @num

我知道这是一个愚蠢的示例,但是我只是在尝试声明一个变量并对其进行处理.我正在尝试使自己熟悉PL/PGSQL.

I know this is a dumb example, but I'm just trying to declare a variable and do something with it. I'm trying to familiarise myself with PL/PGSQL.

再次更新: 又是我.我正在尝试下面的脚本,并得到"[ERROR] 7.0-2:语法错误,意外字符".这是要在PGAdmin中工作吗?

Update, again: It's me again. I'm trying the script below and get a "[ERROR ] 7.0-2: syntax error, unexpected character". Is this meant to work in PGAdmin?

DECLARE num INTEGER; BEGIN num := 3; RAISE NOTICE '%', num; END;

推荐答案

您可以使用do语句.例如:

You can use the do statement. For example:

do $$ declare num integer := 10; begin RAISE INFO 'VARIABLE: %', num; end; $$language plpgsql;

使用pgadmin时,必须使用按钮EXECUTE QUERY代替 执行pdScript,如此处所述:

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

postgresql.1045698.n5.nabble/PgAmin3-Anonymous-code-block-can-t-by-pressed by-pressing-quot-Execute-PG-script -quot-button-td5771073.html

do语句的文档在这里:

The documentation for do statements is here:

www.postgresql/docs/9.3/static/sql-do .html

更多推荐

PGAdmin中的PostgreSQL语法错误

本文发布于:2023-10-13 17:29:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1488634.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语法错误   PGAdmin   PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!