[英]How do I pass a variable into date_part function in postgresql?
I'm passing a variable from my function into the date_part
function but I keep getting a syntax error. 我正在将函数中的变量传递给
date_part
函数,但date_part
收到语法错误。 Tried these 2 examples below and still got a syntax error. 在下面尝试了这两个示例,仍然出现语法错误。
_month = date_part('month', timestamp NEW."sdate");
_month = date_part('month', timestamp format('%s',NEW."sdate"));
Can anyone tell me how do I pass my variable into this function? 谁能告诉我如何将变量传递给此函数?
I think there is no need to use timestamp
literal or format
the string if you need to pass it to date_part
function. 我认为如果需要将
timestamp
字面量传递给date_part
函数,则无需使用timestamp
文字或format
字符串。 If sdate
is of type DATE
, you may use it directly. 如果
sdate
是DATE
类型,则可以直接使用它。
date_part('month',NEW."sdate");
If sdate
is a proper date string such as '2018-01-26 13:15:20', then your first example should work fine - date_part('month', timestamp NEW."sdate");
如果
sdate
是正确的日期字符串,例如'2018-01-26 13:15:20',那么您的第一个示例应该可以正常工作date_part('month', timestamp NEW."sdate");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.