arcgis 属性查询 指定列不存在 a column specified not exist
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了arcgis 属性查询 指定列不存在 a column specified not exist相关的知识,希望对你有一定的参考价值。
arcgis 进行属性查询,数据已经加载,但提示 指定列不存在,什么问题?
你直接在这个地方再试验一下,如果还是报错,你应该看下这个字段到底存在不呢
参考技术A ArcGIS的查询语句跟数据库相关,例如,进行模糊查询:对于Oracle等大型数据库来说应该是如下:
where 项目名称 like '%土地%'-------------用引文单引号。
但是对于个人数据库,即access数据库来说,应该是:
where 项目名称 like '*土地*'
——启发自https://www.cnblogs.com/lovebay/p/6824447.html 参考技术B 你确定查询的列的属性字段是正确的吗?
Postgres 列不存在
【中文标题】Postgres 列不存在【英文标题】:Postgres column does not exist 【发布时间】:2014-11-07 00:29:33 【问题描述】:其他人编写了一个有效的 SQL Server 查询,我负责将其移植到 Postgres。
除了非常基本的 SQL 命令之外,我真的不了解这两个数据库(我正在学习本教程并将继续学习,但我希望尽快解决这个问题)。
无论如何,我得到了第 4 行中的错误,
错误:timeloggedtoday.date_logged 列不存在
我认为来自第 89 行附近的部分(标有 **),但我无法弄清楚语法应该是什么——我尝试复制 WITH/AS文档中的部分,但要么我仍然犯错,要么错误在其他地方。下面可能有很多重复/无关的代码,但我认为最好将它们全部包含在内,因为当我更改为 Postgres 语法时,很容易引入其他错误。
编辑:
如果我删除了有问题的部分,错误将变为
错误:timelogged1daysago.date_logged 列不存在
这是下一批类似的代码,让我相信我在命名临时表时犯了一些语法错误(正确的术语?)但我看不出有什么问题,而且很难找到相关部分在文档中...谷歌搜索“With”或“As”毫无帮助。
SELECT users.author,
users.display_name,
timeloggedToday.date_logged "DATE_LOGGED_TODAY",
timeloggedToday.time_in_hours "TIME_IN_HOURS_TODAY",
timeloggedToday.difference_days "DIFFERENCE_DAYS_TODAY",
CASE
WHEN Ifnull(timeloggedToday.time_in_hours, 0) = 0 THEN 'No Time Logged'
WHEN timeloggedToday.time_in_hours < 3.0 THEN 'User has not logged sufficient time'
ELSE 'user has logged sufficient time'
END "STATUS_TODAY",
timelogged1daysago.date_logged "DATE_LOGGED_1DAYSAGO",
timelogged1daysago.time_in_hours "TIME_IN_HOURS_1DAYSAGO",
timelogged1daysago.difference_days "DIFFERENCE_DAYS_1DAYSAGO",
CASE
WHEN Ifnull(timelogged1daysago.time_in_hours, 0) = 0 THEN 'No Time Logged'
WHEN timelogged1daysago.time_in_hours < 3.0 THEN 'User has not logged sufficient time'
ELSE 'user has logged sufficient time'
END "STATUS_1DAYSAGO",
timelogged2daysago.date_logged "DATE_LOGGED_2DAYSAGO",
timelogged2daysago.time_in_hours "TIME_IN_HOURS_2DAYSAGO",
timelogged2daysago.difference_days "DIFFERENCE_DAYS_2DAYSAGO",
CASE
WHEN Ifnull(timelogged2daysago.time_in_hours, 0) = 0 THEN 'No Time Logged'
WHEN timelogged2daysago.time_in_hours < 3.0 THEN 'User has not logged sufficient time'
ELSE 'user has logged sufficient time'
END "STATUS_2DAYSAGO",
timelogged3daysago.date_logged "DATE_LOGGED_3DAYSAGO",
timelogged3daysago.time_in_hours "TIME_IN_HOURS_3DAYSAGO",
timelogged3daysago.difference_days "DIFFERENCE_DAYS_3DAYSAGO",
CASE
WHEN Ifnull(timelogged3daysago.time_in_hours, 0) = 0 THEN 'No Time Logged'
WHEN timelogged3daysago.time_in_hours < 3.0 THEN 'User has not logged sufficient time'
ELSE 'user has logged sufficient time'
END "STATUS_3DAYSAGO",
timelogged4daysago.date_logged "DATE_LOGGED_4DAYSAGO",
timelogged4daysago.time_in_hours "TIME_IN_HOURS_4DAYSAGO",
timelogged4daysago.difference_days "DIFFERENCE_DAYS_4DAYSAGO",
CASE
WHEN Ifnull(timelogged4daysago.time_in_hours, 0) = 0 THEN 'No Time Logged'
WHEN timelogged4daysago.time_in_hours < 3.0 THEN 'User has not logged sufficient time'
ELSE 'user has logged sufficient time'
END "STATUS_4DAYSAGO",
timelogged5daysago.date_logged "DATE_LOGGED_5DAYSAGO",
timelogged5daysago.time_in_hours "TIME_IN_HOURS_5DAYSAGO",
timelogged5daysago.difference_days "DIFFERENCE_DAYS_5DAYSAGO",
CASE
WHEN Ifnull(timelogged5daysago.time_in_hours, 0) = 0 THEN 'No Time Logged'
WHEN timelogged5daysago.time_in_hours < 3.0 THEN 'User has not logged sufficient time'
ELSE 'user has logged sufficient time'
END "STATUS_5DAYSAGO",
timelogged6daysago.date_logged "DATE_LOGGED_6DAYSAGO",
timelogged6daysago.time_in_hours "TIME_IN_HOURS_6DAYSAGO",
timelogged6daysago.difference_days "DIFFERENCE_DAYS_6DAYSAGO",
CASE
WHEN Ifnull(timelogged6daysago.time_in_hours, 0) = 0 THEN 'No Time Logged'
WHEN timelogged6daysago.time_in_hours < 3.0 THEN 'User has not logged sufficient time'
ELSE 'user has logged sufficient time'
END "STATUS_6DAYSAGO",
timelogged7daysago.date_logged "DATE_LOGGED_7DAYSAGO",
timelogged7daysago.time_in_hours "TIME_IN_HOURS_7DAYSAGO",
timelogged7daysago.difference_days "DIFFERENCE_DAYS_7DAYSAGO",
CASE
WHEN Ifnull(timelogged7daysago.time_in_hours, 0) = 0 THEN 'No Time Logged'
WHEN timelogged7daysago.time_in_hours < 3.0 THEN 'User has not logged sufficient time'
ELSE 'user has logged sufficient time'
END "STATUS_7DAYSAGO",
lastReportedTime.last_time_logged
FROM
(SELECT lower_child_name AS "author",
cwd_user.display_name
FROM cwd_membership
LEFT JOIN cwd_user ON (cwd_membership.lower_child_name = cwd_user.user_name
AND cwd_user.directory_id = cwd_membership.directory_id)
WHERE lower_parent_name = 'jira-developers'
AND cwd_membership.directory_id = 10100) users
**LEFT JOIN
(SELECT app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d') AS "DATE_LOGGED",
Sum(timeworked) / 3600 "TIME_IN_HOURS",
startdate - Now() "DIFFERENCE_DAYS"
FROM worklog
LEFT JOIN app_user ON worklog.author = app_user.user_key
WHERE to_char(Now() - INTERVAL '8 days', '%Y-%m-%d') < to_char(startdate, '%Y-%m-%d')
AND startdate - Now() = INTERVAL '0 days'
GROUP BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now()),
worklog.startdate
ORDER BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now())) timeloggedToday ON timeloggedToday.lower_user_name = users.author**
LEFT JOIN
(SELECT app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d') AS "DATE_LOGGED",
Sum(timeworked) / 3600 "TIME_IN_HOURS",
startdate - Now() "DIFFERENCE_DAYS"
FROM worklog
LEFT JOIN app_user ON worklog.author = app_user.user_key
WHERE to_char(Now() - INTERVAL '8 days', '%Y-%m-%d') < to_char(startdate, '%Y-%m-%d')
AND startdate - Now() = INTERVAL '-1 days'
GROUP BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now()),
worklog.startdate
ORDER BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now())) timelogged1daysago ON timelogged1daysago.lower_user_name = users.author
LEFT JOIN
(SELECT app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d') AS "DATE_LOGGED",
Sum(timeworked) / 3600 "TIME_IN_HOURS",
startdate - Now() "DIFFERENCE_DAYS"
FROM worklog
LEFT JOIN app_user ON worklog.author = app_user.user_key
WHERE to_char(Now() - INTERVAL '8 days', '%Y-%m-%d') < to_char(startdate, '%Y-%m-%d')
AND startdate - Now() = INTERVAL '-2 days'
GROUP BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now()),
worklog.startdate
ORDER BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now())) timelogged2daysago ON timelogged2daysago.lower_user_name = users.author
LEFT JOIN
(SELECT app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d') AS "DATE_LOGGED",
Sum(timeworked) / 3600 "TIME_IN_HOURS",
startdate - Now() "DIFFERENCE_DAYS"
FROM worklog
LEFT JOIN app_user ON worklog.author = app_user.user_key
WHERE to_char(Now() - INTERVAL '8 days', '%Y-%m-%d') < to_char(startdate, '%Y-%m-%d')
AND startdate - Now() = INTERVAL '-3 days'
GROUP BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now()),
worklog.startdate
ORDER BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now())) timelogged3daysago ON timelogged3daysago.lower_user_name = users.author
LEFT JOIN
(SELECT app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d') AS "DATE_LOGGED",
Sum(timeworked) / 3600 "TIME_IN_HOURS",
startdate - Now() "DIFFERENCE_DAYS"
FROM worklog
LEFT JOIN app_user ON worklog.author = app_user.user_key
WHERE to_char(Now() - INTERVAL '8 days', '%Y-%m-%d') < to_char(startdate, '%Y-%m-%d')
AND startdate - Now() = INTERVAL '-4 days'
GROUP BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now()),
worklog.startdate
ORDER BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now())) timelogged4daysago ON timelogged4daysago.lower_user_name = users.author
LEFT JOIN
(SELECT app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d') AS "DATE_LOGGED",
Sum(timeworked) / 3600 "TIME_IN_HOURS",
startdate - Now() "DIFFERENCE_DAYS"
FROM worklog
LEFT JOIN app_user ON worklog.author = app_user.user_key
WHERE to_char(Now() - INTERVAL '8 days', '%Y-%m-%d') < to_char(startdate, '%Y-%m-%d')
AND startdate - Now() = INTERVAL '-5 days'
GROUP BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now()),
worklog.startdate
ORDER BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now())) timelogged5daysago ON timelogged5daysago.lower_user_name = users.author
LEFT JOIN
(SELECT app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d') AS "DATE_LOGGED",
Sum(timeworked) / 3600 "TIME_IN_HOURS",
startdate - Now() "DIFFERENCE_DAYS"
FROM worklog
LEFT JOIN app_user ON worklog.author = app_user.user_key
WHERE to_char(Now() - INTERVAL '8 days', '%Y-%m-%d') < to_char(startdate, '%Y-%m-%d')
AND startdate - Now() = INTERVAL '-6 days'
GROUP BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now()),
worklog.startdate
ORDER BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now())) timelogged6daysago ON timelogged6daysago.lower_user_name = users.author
LEFT JOIN
(SELECT app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d') AS "DATE_LOGGED",
Sum(timeworked) / 3600 "TIME_IN_HOURS",
startdate - Now() "DIFFERENCE_DAYS"
FROM worklog
LEFT JOIN app_user ON worklog.author = app_user.user_key
WHERE to_char(Now() - INTERVAL '8 days', '%Y-%m-%d') < to_char(startdate, '%Y-%m-%d')
AND startdate - Now() = INTERVAL '-7 days'
GROUP BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now()),
worklog.startdate
ORDER BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now())) timelogged7daysago ON timelogged7daysago.lower_user_name = users.author
LEFT JOIN
(SELECT app_user.lower_user_name,
Max(startdate) AS "last_time_logged"
FROM worklog
LEFT JOIN app_user ON worklog.author = app_user.user_key
GROUP BY app_user.lower_user_name) lastReportedTime ON lastReportedTime.lower_user_name = users.author
编辑:更简单的查询
我想我已经编辑掉了一些无关的东西,希望能找到这个错误。无论如何,这个较短的查询至少给了我同样的错误,所以也许这更容易帮助我调试:
SELECT users.author,
users.display_name,
timeloggedToday.date_logged "DATE_LOGGED_TODAY",
timeloggedToday.time_in_hours "TIME_IN_HOURS_TODAY",
timeloggedToday.difference_days "DIFFERENCE_DAYS_TODAY",
CASE
WHEN Ifnull(timeloggedToday.time_in_hours, 0) = 0 THEN 'No Time Logged'
WHEN timeloggedToday.time_in_hours < 3.0 THEN 'User has not logged sufficient time'
ELSE 'user has logged sufficient time'
END "STATUS_TODAY",
lastReportedTime.last_time_logged
FROM
(SELECT lower_child_name AS "author",
cwd_user.display_name
FROM cwd_membership
LEFT JOIN cwd_user ON (cwd_membership.lower_child_name = cwd_user.user_name
AND cwd_user.directory_id = cwd_membership.directory_id)
WHERE lower_parent_name = 'jira-developers'
AND cwd_membership.directory_id = 10100) users
LEFT JOIN
(SELECT app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d') AS "DATE_LOGGED",
Sum(timeworked) / 3600 "TIME_IN_HOURS",
startdate - Now() "DIFFERENCE_DAYS"
FROM worklog
LEFT JOIN app_user ON worklog.author = app_user.user_key
WHERE to_char(Now() - INTERVAL '8 days', '%Y-%m-%d') < to_char(startdate, '%Y-%m-%d')
AND startdate - Now() = INTERVAL '0 days'
GROUP BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now()),
worklog.startdate
ORDER BY app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d'),
Date(Now())) timeloggedToday ON timeloggedToday.lower_user_name = users.author
LEFT JOIN
(SELECT app_user.lower_user_name,
Max(startdate) AS "last_time_logged"
FROM worklog
LEFT JOIN app_user ON worklog.author = app_user.user_key
GROUP BY app_user.lower_user_name) lastReportedTime ON lastReportedTime.lower_user_name = users.author
【问题讨论】:
显示\d timeloggedtoday
的输出
多么可怕的查询。我相信它可以做得比这更令人愉快。带有一些示例数据的sqlfiddle.com 将非常有帮助。
是的,不是我写的。好吓人。不过,这是非常重复的,所以它并不像看起来那么糟糕。 @AlexDvoretsky,对不起,我对这一切都很陌生,不明白你在问什么。
@thumbtackthief 他要求您连接psql
命令行客户端并运行\d timeloggedtoday
以显示表定义。当然,既然没有这样的表不工作;您需要 \d worklog
和 \d app_user
来显示基础表。
命令行客户端不适合我。我会继续努力让它发挥作用。
【参考方案1】:
编辑:
引用的大写正在破坏查询。在下面第二次失败的输出中,您可以看到 Postgres 不喜欢大写字母。除非你强制使用 "
引号,否则它习惯于将所有内容都小写。
--fails
select a
from
(select 1 as "A") as t;
--fails
select A
from
(select 1 as "A") as t;
--works
select "A"
from
(select 1 as "A") as t;
psql:new.sql:5: ERROR: column "a" does not exist
LINE 1: select a
^
psql:new.sql:10: ERROR: column "a" does not exist
LINE 1: select A
^
A
───
1
(1 row)
select ...
timeloggedToday.date_logged "DATE_LOGGED_TODAY",
-- should be: timeloggedToday."DATE_LOGGED" "DATE_LOGGED_TODAY",
...
LEFT JOIN
(SELECT app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d') AS "DATE_LOGGED",
Sum(timeworked) / 3600 "TIME_IN_HOURS",
startdate - Now() "DIFFERENCE_DAYS"
...
) timeloggedToday ON timeloggedToday.lower_user_name = users.author;
我会考虑去掉大写和引号。只会让人头疼。作为旁注,您可以通过以下方式编写一次左连接:
-- instead of enumerating each possible interval
WHERE to_char(Now() - INTERVAL '8 days', '%Y-%m-%d') < to_char(startdate, '%Y-%m-%d')
-- select the interval
now()::date - start_date as diff
-- then build up your columns like:
case(case when diff=0 then date_logged else null end) as date_logged_today
case(case when diff=1 then date_logged else null end) as date_logged_yesterday
-- and so on ...
你也可以做
CASE
WHEN Ifnull(timeloggedToday.time_in_hours, 0) = 0 THEN 'No Time Logged'
WHEN timeloggedToday.time_in_hours < 3.0 THEN 'User has not logged sufficient time'
ELSE 'user has logged sufficient time'
END "STATUS_TODAY",
变成一个函数来摆脱繁琐的冗余。
【讨论】:
我很可能误解了这一点,但我认为问题在于没有正确创建 timeloggedToday 的别名。 (timelogged1daysago 也会触发相同的错误,其他类似的别名也会触发相同的错误,但它首先会触发 timeloggedToday,我几乎可以肯定它们将是相同的语法错误原因) 是的,你是对的。当我第一次看到它时,我以为您在查询显示的内容。 嘿,它有效!好吧,我还是收到了一条新的错误消息。抱怨第 8 行中的 Ifnull。不过,我要给你赏金——非常感谢! 在文档中查找 coalesce()以上是关于arcgis 属性查询 指定列不存在 a column specified not exist的主要内容,如果未能解决你的问题,请参考以下文章