인용된 테이블 식별자를 사용할 때 Informix의 CONNECT BY 쿼리에서 일반 구문 오류가 발생합니다.
-
21-12-2019 - |
문제
Informix 데이터베이스에서 다음 쿼리를 실행할 때 데이터베이스는 문제의 원인에 대한 표시 없이 일반 구문 오류를 보고합니다.동일한 쿼리가 CUBRID 또는 Oracle 데이터베이스에서 완벽하게 실행됩니다. 두 데이터베이스 모두 다음을 지원합니다. CONNECT BY
통사론:
select
lower(connect_by_root "t_directory"."name"),
connect_by_isleaf,
connect_by_iscycle,
substr(
sys_connect_by_path(lower("t_directory"."name"), '/'),
2) "dir"
from "t_directory"
start with "t_directory"."parent_id" is null
connect by nocycle prior "t_directory"."id" = "t_directory"."parent_id"
order siblings by lower("t_directory"."name") asc
내가 사용하고 있는 데이터베이스는 Windows용 Informix 12.10 Developer Edition입니다.다음 연결 URL을 사용하여 JDBC 드라이버에서 쿼리를 실행하고 있습니다(인용된 테이블 식별자를 허용하기 위해).
jdbc:informix-sqli://localhost:9092/test:INFORMIXSERVER=ol_informix;DELIMIDENT=y
해결책
여기서 정확한 문제는 다음과 같습니다. prior
인용된 열 식별자는 괜찮은 것처럼 보이지만 인용된 테이블 식별자는 허용되지 않습니다.이 쿼리는 완벽하게 잘 실행됩니다.
select
lower(connect_by_root "t_directory"."name"),
connect_by_isleaf,
connect_by_iscycle,
substr(
sys_connect_by_path(lower("t_directory"."name"), '/'),
2) "dir"
from "t_directory"
start with "t_directory"."parent_id" is null
connect by nocycle prior t_directory."id" = "t_directory"."parent_id"
order siblings by lower("t_directory"."name") asc
...차이점은 다음과 같습니다.
-- Bad:
connect by nocycle prior "t_directory"."id" = "t_directory"."parent_id"
-- Good:
connect by nocycle prior t_directory."id" = "t_directory"."parent_id"
제휴하지 않습니다 StackOverflow