PostgreSQL: 月 := 间隔 '30 天';
尝试从 2 个表中删除超过 1 个月的记录,其中 1 引用另一个表中的“id”列:
create or replace function quincytrack_clean()
returns void as $BODY$
begin
month := interval '30 days';
delete from hide_id
where id in
(select id from quincytrack
where age(QDATETIME) > month);
delete from quincytrack
where age(QDATETIME) > month;
end;
$BODY$ language plpgsql;
但这失败了:
ERROR: syntax error at or near "month"
LINE 1: month := interval '30 days'
^
QUERY: month := interval '30 days'
CONTEXT: SQL statement in PL/PgSQL function "quincytrack_clean" near line 2
我正在阅读 文档,但不明白我的声明有什么问题......
Trying to delete records older than 1 month from 2 tables, where 1 references the "id" column in another:
create or replace function quincytrack_clean()
returns void as $BODY$
begin
month := interval '30 days';
delete from hide_id
where id in
(select id from quincytrack
where age(QDATETIME) > month);
delete from quincytrack
where age(QDATETIME) > month;
end;
$BODY$ language plpgsql;
but this fails with:
ERROR: syntax error at or near "month"
LINE 1: month := interval '30 days'
^
QUERY: month := interval '30 days'
CONTEXT: SQL statement in PL/PgSQL function "quincytrack_clean" near line 2
I'm reading the doc, but don't understand what's wrong with my declaration...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要声明变量“month”,即:
此外,您可能需要重新检查您的“where”标准。如果 QDATETIME 是索引列,我认为它不会使用索引,而 QDATETIME
QDATETIME
QDATETIME
QDATETIME
QDATETIME
QDATETIME
QDATETIME
(现在()-月份)
会的。You need to declare the variable 'month', viz.:
Also, you might want to re-examine your "where" criteria. If QDATETIME is an indexed column, I don't think it will use the index, whereas
QDATETIME < (now() - month)
would.您需要先声明该变量,然后才能使用它。
但我会避免使用保留字或内部函数名称的变量名称。
You need to declare the variable before you can use it.
But I would avoid using variable names that are reserved words or internal function names.