使用 psql 编写 for 循环
我正在尝试通过 psql
< 运行 for 循环Linux 中的 /a> 命令在 PostGIS 数据库中执行一些空间操作
我在 dbeaver 中成功运行的 My SQL 命令看起来像这样
DO $$
declare
the_name varchar(50);
BEGIN
FOR the_name IN
SELECT "name" FROM myschema.mytable WHERE "idcolumn" = 'selected id' LIMIT 4
LOOP
some operations inside the loop...
END LOOP;
RAISE NOTICE 'the name - (%)', the_name;
END;
$$;
我通常将 dbeaver SQL 命令复制粘贴到 psql -c
中并运行美好的。但我在使用上面的代码时遇到语法错误。我是 SQL 初学者,非常感谢任何帮助。谢谢。
编辑
这是错误消息 - 这很奇怪,因为我的代码中没有这个数字。它可能是从记忆中读取或其他东西。
ERROR: syntax error at or near "377643"
LINE 1: DO 377643 declare the_name varchar(50); BEGIN FOR the_...
I am trying to run a for loop via psql
command in Linux to do some spatial operations in PostGIS database
My SQL command which I successfully ran in dbeaver looks something like this
DO $
declare
the_name varchar(50);
BEGIN
FOR the_name IN
SELECT "name" FROM myschema.mytable WHERE "idcolumn" = 'selected id' LIMIT 4
LOOP
some operations inside the loop...
END LOOP;
RAISE NOTICE 'the name - (%)', the_name;
END;
$;
I usually copy-paste the dbeaver SQL command inside psql -c
and it runs fine. But I am getting a syntax error when using the above code. I am a beginner in SQL and any help is appreciated. Thanks.
Edit
This is the error message - it's weird because I don't have this number in the code. It's probably reading from memory or something.
ERROR: syntax error at or near "377643"
LINE 1: DO 377643 declare the_name varchar(50); BEGIN FOR the_...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论