我在shell存档中有这个命令:
sh -c $POSTGRESbin'psql -U '$POSTGRESuser' -h localhost -d '$POSTGRESdb' -c "select preview from '$fildCatalog' where preview <>'nodata' and id_registro in (select distinct(id_record) from e3_article_items where id_catalog=2101 and id_article in (select id_article from document_articles where id_document in(select distinct(id_document) from p3_logical_pages where id_logical_page in (select id_logical_page from p3_flatplan_pages where id_edition=1536 and id_logical_page is not null order by cast(pagenumber as numeric)))));"' > $queryFolder$highFile"_"$previewFile;
但在&lt;&gt;'nodata'中出现错误,我不知道如何解决它。错误是:
ERROR: column "nodata" does not exist
LINE 1: select preview from XT_FIJOS where preview <>nodata and id_r...
任何人都可以帮助我吗?
谢谢!! ^
答案 0 :(得分:0)
问题是你使用'...'
来引用shell命令的部分内容,所以你不能在命令的那些部分使用它们 。因此,您的SQL查询包含nodata
而不是'nodata'
,因此它认为nodata
应该是列名。
要解决此问题,您可以在需要时使用"..."
代替'...'
:
sh -c "${POSTGRESbin}psql -U $POSTGRESuser -h localhost -d $POSTGRESdb -c \"select preview from '$fildCatalog' where preview <> 'nodata' and id_registro in (select distinct(id_record) from e3_article_items where id_catalog=2101 and id_article in (select id_article from document_articles where id_document in(select distinct(id_document) from p3_logical_pages where id_logical_page in (select id_logical_page from p3_flatplan_pages where id_edition=1536 and id_logical_page is not null order by cast(pagenumber as numeric)))));\"" > "$queryFolder${highFile}_$previewFile";
(请注意"..."
可以使用"
包含文字\"
,这会使其更加灵活。)
答案 1 :(得分:0)
这是正确的方法:
sh -c $POSTGRESbin'psql -U '$POSTGRESuser' -h localhost -d '$POSTGRESdb' -c "select preview from '$fildCatalog' where preview <>'\'nodata\'' and id_registro in (select distinct(id_record) from e3_article_items where id_catalog=2101 and id_article in (select id_article from document_articles where id_document in(select distinct(id_document) from p3_logical_pages where id_logical_page in (select id_logical_page from p3_flatplan_pages where id_edition=1536 and id_logical_page is not null order by cast(pagenumber as numeric)))));"' > $queryFolder$previewFile"_"$fildCatalog;
感谢您的帮助!