sql - 无法使用 knes 从 postgres 获取当前时间戳
问题描述
我正在使用 knex 并使用原始查询来获取 postgres 数据库的当前时间戳。我在用
knex.raw('select now()').then(function(resp)
{
console.log(resp)
})
但我无法得到想要的结果。请告诉我能做什么的解决方案。
解决方案
这应该这样做:
knex.select(knex.fn.now()).then(res => console.log(res[0].now));
也许你也应该告诉你想要的结果是什么。
编辑:编辑查询以实际从响应中获取行和列,因为select CURRENT_TIMESTAMP;
在 postgres 上返回以下内容:
mikaelle=# select CURRENT_TIMESTAMP;
now
-------------------------------
2018-12-10 14:48:01.472945+02
(1 row)
推荐阅读
- python - 无法使用 Python SMTPD 模块启动本地 SMTP 调试服务器
- keycloak - 从 Keycloak 登录:如何从 KEYCLOAK_IDENTITY/KC_RESTART cookie 获取承载令牌
- node.js - 无法在 Nodejs 应用程序中检索 cloudWatch GetMetricData
- automation - 如何在 jest puppeteer 测试自动化框架中从 excel 中读取/写入数据
- r - 如何手动将置信区间添加到预测值
- xamarin.android - 使用 Android API 30 (Android 11) 通过 Xamarin android 应用程序将文件附加到电子邮件
- visual-studio - 如何在 Visual Studio 中将包含目录从一个项目继承到另一个项目?
- javascript - 猫鼬 findOne 发送 null
- javascript - 为什么 HTML div 元素在移动设备上旋转奇怪?
- string - 如何在Powershell中用&而不是&替换字符串