Postgresql SQL Insert在i上失败。在插入期间,名称似乎不存在

Postgresql SQL Insert在i上失败。在插入期间,名称似乎不存在,postgresql,sql-insert,postgresql-9.5,Postgresql,Sql Insert,Postgresql 9.5,我正在使用PostgresSQL和pgAdmin。我正在尝试使用INSERT INTO和SELECT FROM语句在暂存表和生产表之间复制数据,同时使用to_字符。这可能是,也可能不是错误的方法。选择失败,因为显然“第i列日期不存在” 问题是:为什么我会得到“I列日期不存在” 除了日期转换之外,这两个表的架构是相同的 我尝试过匹配表的模式,但to_char转换除外。我已经检查并再次检查该列是否存在 这是我正在尝试的代码: INSERT INTO weathergrids (location, d

我正在使用PostgresSQL和pgAdmin。我正在尝试使用INSERT INTO和SELECT FROM语句在暂存表和生产表之间复制数据,同时使用to_字符。这可能是,也可能不是错误的方法。选择失败,因为显然“第i列日期不存在”

问题是:为什么我会得到“I列日期不存在”

除了日期转换之外,这两个表的架构是相同的

我尝试过匹配表的模式,但to_char转换除外。我已经检查并再次检查该列是否存在

这是我正在尝试的代码:

INSERT INTO weathergrids (location, dates, temperature, rh, wd, ws, df, cu, cc)
  SELECT
    i.location AS location,
    i.dates as dates,
    i.temperature as temperature,
    i.rh as rh,
    i.winddir as winddir,
    i.windspeed as windspeed, 
    i.droughtfactor as droughtfactor,
    i.curing as curing,
    i.cloudcover as cloudcover
  FROM (
      SELECT location, 
             to_char(to_timestamp(dates, 'YYYY-DD-MM HH24:MI'), 'HH24:MI YYYY-MM-DD HH24:MI'), 
             temperature, rh, wd, ws, df, cu, cc 
       FROM wosweathergrids
  ) i;
我收到的错误是:

ERROR:  column i.dates does not exist
LINE 4:  i.dates as dates,
         ^
SQL state: 42703
Character: 151
我的数据架构如下所示:


+-----------------+-----+-------------+-----------------------------+-----+
|      TABLE      | NUM |   COLNAME   |          DATATYPE           | LEN |
+-----------------+-----+-------------+-----------------------------+-----+
| weathergrids    |   1 | id          | integer                     |  32 |
| weathergrids    |   2 | location    | numeric                     |   6 |
| weathergrids    |   3 | dates       | timestamp without time zone |     |
| weathergrids    |   4 | temperature | numeric                     |   3 |
| weathergrids    |   5 | rh          | numeric                     |   4 |
| weathergrids    |   6 | wd          | numeric                     |   4 |
| weathergrids    |   7 | wsd         | numeric                     |   4 |
| weathergrids    |   8 | df          | numeric                     |   4 |
| weathergrids    |   9 | cu          | numeric                     |   4 |
| weathergrids    |  10 | cc          | numeric                     |   4 |
| wosweathergrids |   1 | id          | integer                     |  32 |
| wosweathergrids |   2 | location    | numeric                     |   6 |
| wosweathergrids |   3 | dates       | character varying           |  16 |
| wosweathergrids |   4 | temperature | numeric                     |   3 |
| wosweathergrids |   5 | rh          | numeric                     |   4 |
| wosweathergrids |   6 | wd          | numeric                     |   4 |
| wosweathergrids |   7 | ws          | numeric                     |   4 |
| wosweathergrids |   8 | df          | numeric                     |   4 |
| wosweathergrids |   9 | cu          | numeric                     |   4 |
| wosweathergrids |  10 | cc          | numeric                     |   4 |
+-----------------+-----+-------------+-----------------------------+-----+

名为
i
的派生表(子查询)没有名为
dates
的列,因为该列
dates
to_char()
函数中“隐藏”,并且由于它没有为该表达式定义别名,因此派生表的“外部”没有可用的列
dates

但我看不出为什么要从派生表开始。另外:使用相同名称的列别名也是不必要的。
i.location as location
i.location
完全相同

因此,您的查询可以简化为:

插入天气栅格(位置、日期、温度、相对湿度、wd、ws、df、cu、cc)
挑选
位置,
to_时间戳(日期“YYYY-DD-MM HH24:MI”),
温度,
嗯,
温迪尔,
风速,
干旱因子,
固化,
云层
从WoweatherGrids
您不需要为
to_timestamp()
表达式指定别名,因为在
插入中,列是按位置匹配的,而不是按名称匹配的。。。选择
语句。

名为
i
的派生表(子查询)没有名为
dates
的列,因为
dates
列在
to_char()
函数中是“隐藏”的,并且它没有为该表达式定义别名,因此在派生表的“外部”没有可用的列
dates

但我看不出为什么要从派生表开始。另外:使用相同名称的列别名也是不必要的。
i.location as location
i.location
完全相同

因此,您的查询可以简化为:

插入天气栅格(位置、日期、温度、相对湿度、wd、ws、df、cu、cc)
挑选
位置,
to_时间戳(日期“YYYY-DD-MM HH24:MI”),
温度,
嗯,
温迪尔,
风速,
干旱因子,
固化,
云层
从WoweatherGrids
您不需要为
to_timestamp()
表达式指定别名,因为在
插入中,列是按位置匹配的,而不是按名称匹配的。。。选择
语句