使用 php pg_query_params 将 unix 秒转换为 postgres 时间戳
unix second into postgres timestamp using php pg_query_params
我想使用 PHP pg_query_params 方法将 unix 时间戳值插入到 postgres 时间戳列中,但是卡住了。
这是不完整的代码:
$con = pg_connect(...);
$stmt = 'INSERT INTO my_table (submitted) VALUES ()';
$ts = 1479939387;
$values = [translate_timestamp_into_sth_postgres_accepts($ts)];
$res = pg_query_params($con, $stmt, $values);
问:如何将unix秒值转换成sth。 postgres 接受吗?
使用函数to_timestamp(double precision)
:
select to_timestamp(1479939387) at time zone 'utc' as tstamp;
tstamp
---------------------
2016-11-23 22:16:27
(1 row)
您的代码可能如下所示(使用默认时区):
$con = pg_connect(...);
$stmt = 'INSERT INTO my_table (submitted) VALUES (to_timestamp())';
$ts = 1479939387;
$res = pg_query_params($con, $stmt, $ts);
我想使用 PHP pg_query_params 方法将 unix 时间戳值插入到 postgres 时间戳列中,但是卡住了。
这是不完整的代码:
$con = pg_connect(...);
$stmt = 'INSERT INTO my_table (submitted) VALUES ()';
$ts = 1479939387;
$values = [translate_timestamp_into_sth_postgres_accepts($ts)];
$res = pg_query_params($con, $stmt, $values);
问:如何将unix秒值转换成sth。 postgres 接受吗?
使用函数to_timestamp(double precision)
:
select to_timestamp(1479939387) at time zone 'utc' as tstamp;
tstamp
---------------------
2016-11-23 22:16:27
(1 row)
您的代码可能如下所示(使用默认时区):
$con = pg_connect(...);
$stmt = 'INSERT INTO my_table (submitted) VALUES (to_timestamp())';
$ts = 1479939387;
$res = pg_query_params($con, $stmt, $ts);