我有一个包含时间戳数组的表,如下所示:
CREATE TABLE start_times
(
start_date timestamp[]
);
Run Code Online (Sandbox Code Playgroud)
我不确定如何将时间戳值插入到数组中。我在一篇文章中读到,在将时间戳插入数组时,我应该使用双引号而不是单引号,如下所示:
INSERT INTO start_times VALUES (ROW('{{"10-JAN-15 12.51.14.340358000 AM"},{"11-JAN-15 12.51.14.340358000 AM"}}'));
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试时,出现以下错误:
ERROR: invalid input syntax for type timestamp: "10-JAN-15 12.51.14.340358000 AM"
SQL state: 22007
Character: 165
Run Code Online (Sandbox Code Playgroud)
有人能告诉我如何将时间戳值插入时间戳数组吗?
我有一个 Symfony 2.8 应用程序,它使用Gedmo\Timestampable自动created_at和操作的注释,但它似乎在首次创建实体/行时updated_at将相同的时间戳放入列中。updated_atAnUPDATE确实会导致该updated_at列显示较新的时间戳,但我希望它一开始就为空白。
我的理解是,在 上INSERT,只有created_at列应该填充时间戳,并且updated_at应该保持空白,因为它尚未更新。只有在该列第一次更新后才可以获得更新时间的值。
我的预期正确吗?我的代码/配置有问题吗?或者这个注释实际上是否按设计设置了两列的值?
我的config.yml:
...
stof_doctrine_extensions:
default_locale: "%locale%"
translation_fallback: true
orm:
default:
translatable: true
timestampable: true
...
Run Code Online (Sandbox Code Playgroud)
我的实体:
...
/**
* An automatic timestamp of the creation.
*
* @var \DateTime $createdAt
* @Gedmo\Timestampable(on="create")
* @ORM\Column(name="created_at", type="datetime")
*/
public $createdAt;
/**
* An automatic timestamp of the updation.
*
* @var \DateTime $updatedAt
* @Gedmo\Timestampable(on="update")
* …Run Code Online (Sandbox Code Playgroud) 我在我的一个表中使用时间戳列,并使用自动更新功能。这是我的表架构:
mysql> desc user_rides;
+------------+--------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+-------------------+-----------------------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| user_id | int(11) | NO | MUL | NULL |
| ride_cnt | int(11) | YES | | NULL | |
| created_at | timestamp | NO | | CURRENT_TIMESTAMP | |
| updated_at | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+------------+--------------+------+-----+-------------------+-----------------------------+ …Run Code Online (Sandbox Code Playgroud) 我正在尝试重命名数据库中表的时间戳列(created_at和updated_at) 。user我已经看到了这个答案,但是当我重写CREATED_AT和UPDATED_AD常量时:
class User extends Authenticatable
{
const CREATED_AT = 'user_creation_date';
const UPDATED_AT = 'user_update_date';
...
}
Run Code Online (Sandbox Code Playgroud)
它所做的只是重命名模型的属性User,即$user->user_creation_date和$user->user_update_date。数据库列保持不变。我应该如何重命名数据库的列,同时保留自动更新功能?
感谢您的帮助。
我有一个纪元格式的时间戳,如下所示:1551187548876。如果我使用https://www.epochconverter.com/将其转换为时间戳,我会得到正确的时间。
但是,如果我使用 PostgreSQL 将其转换为时间to_timestamp,我会得到以下结果:
select to_timestamp(1551187548876) from my_table;
51125-03-06 14:14:36+00
Run Code Online (Sandbox Code Playgroud)
问题
如何1551187548876在 PostgreSQL 中将纪元转换为时间戳?
在 MySQL 中,我有很多列的表。如何获取所有具有时间戳数据类型的列名?我想对数据库中的所有表执行此操作。
时间戳列的数据类型可以是 TIMESTAMP 或 TIMESTAMP(6)。
输出如下所示:
table_name | column_name | data type |
-----------------------------------------
tabe01 | column01 | timestamp |
tabe02 | column03 | timestamp(6) |
tabe03 | column02 | timestamp |
tabe04 | column05 | timestamp |
Run Code Online (Sandbox Code Playgroud) 我必须更新数据库中的时间戳,但我只想更改时间,保留曾经注册的日期,例如,在“2021-10-07 11:00:00”中,我想将其更新为“2021-” 10-07 10:00:00',我怎样才能做到这一点?
我尝试运行的查询:
update p_bab.registro_ponto
set data_hora = timestamp::'10:00:00'
where id = 50;
Run Code Online (Sandbox Code Playgroud) Is it possible to use COALESCE (or any other way) to replace NULL values from a TIMESTAMP column with a string like 'N/A'?
In my SELECT statement I have a
CASE WHEN n.expiration_date::date IS NULL THEN 'N/A' ELSE n.expiration_date::date END
Run Code Online (Sandbox Code Playgroud)
When I try this, I get this error, which makes sense:
invalid input syntax for type date: "N/A"
I found this blog post too about this problem. Is there a way around it?
如何使用 java.sql.Timestamp; 获取当前时间戳 - x 周数;
这是我当前的时间戳Timestamp.from(Instant.now(clock));
x- 可以是 0-5 之间的任意数字