2012-10-25 41 views
0

我在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; 

但<>「無數據」出現錯誤,我不知道我怎麼能解決這個問題。錯誤是:

ERROR: column "nodata" does not exist 
LINE 1: select preview from XT_FIJOS where preview <>nodata and id_r... 

任何人都可以幫我嗎?

謝謝! ^

回答

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"; 

+0

謝謝,但我試圖用「......」和它的同一個問題: LINE 1:... LECT預覽從XT_HOUSE_PHOTOS其中預覽<>‘無數據’一... ^ 待辦事項你知道任何方式來「逃避」引用'...'? 謝謝 – jask

+0

@jask:我的答案現在包含* should *版本。 – ruakh

+0

是的,抱歉,我沒有看到它,但不起作用:(。現在出現:LINE 1:...從XT_HOUSE_PHOTOS預覽<>「nodata」... lect預覽... – jask

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; 

感謝您的幫助!