SELECT NOW() - INTERVAL '$1 DAY';
我不明白为什么这个查询有效。查询中存在无效的 $ 文字。
最佳答案
当解析 timestamp
或 interval
值时,PostgreSQL 会忽略不是 +
、-
、.
,一个数字或一个字母字符。
参见 src/backend/utils/adt/datetime.c
中的 ParseDateTime
:
/* ignore other punctuation but use as delimiter */
else if (ispunct((unsigned char) *cp))
{
cp++;
continue;
}
来自 man ispunct
:
ispunct()
checks for any printable character which is not a space or an
alphanumeric character.
关于database - 这个 postgres 查询是怎么工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50153122/