如何在 table 名称中包含当前时间 - postgresql

how to include current time in table name - postgresql

有什么方法可以更改此 sql 语句,以便生成的 table 具有作为 table 名称的一部分的时间戳:

CREATE TABLE public.mytesttable (LIKE  public.tabletobackup INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES);

所以不仅仅是

 mytesttable

我想要

 mytesttable_20170131151515

我想在同一个数据库中备份一个 table... 我被要求在 table 名称中包含当前的 date/time。

如有任何提示,我们将不胜感激。谢谢。

像这里一样使用动态 sql:

vao=# do $$ begin execute format('create table "date_%s" (i int)',now()::date); end; $$;
DO
vao=# \dt+ "date_2017-01-31"
                        List of relations
 Schema |      Name       | Type  | Owner |  Size   | Description
--------+-----------------+-------+-------+---------+-------------
 public | date_2017-01-31 | table | vao   | 0 bytes |
(1 row)