sql - Postgresql error: "failed to find conversion function from unknown to text" -


i have following postgresql query:

       (           select '201405mase04' testid, count(*) totq, count(distinct case when se1 = '' null else se1 end) totse,                   case when count(*)=0 7 else count(distinct rc) end totrc           eivtestitems ti, eivtests t            ti.test_id = t.test_id                   , t.test_type_id = 1                  , t.test_id=  '201405mase04'                  , ti.omit <> 1    ),     b     (           select '201405mase04' testid, count(*) totq           eivtestitems ti, eivtests t            ti.test_id = t.test_id                   , t.test_type_id = 1                  , t.test_id=  '201405mase04'                  , ti.omit = 1    ),    c    (           select '201405mase04' testid, count(*) totq           eivtestitems ti, eivtests t            ti.test_id = t.test_id                   , t.test_type_id = 1                  , t.test_id=  '201405mase04'                  , ti.question_type_id='2'    )     select a.testid, a.totq + coalesce(b.totq,0) - coalesce(c.totq,0) totq, a.totse, a.totrc       left outer join b on a.testid = b.testid    left outer join c on a.testid = c.testid 

when trying run query, throwing me following error:

error:  failed find conversion function unknown text  ********** error **********  error: failed find conversion function unknown text sql state: xx000 

how find out getting conversion error here?

it looks postgres doesn't constant '201405mase04'.

sql fiddle demo generates same error get.

sql fiddle demo showing cast datatype fixes issue.

try this. define text

with     (           select cast('201405mase04' text) testid, count(*) totq, count(distinct case when se1 = '' null else se1 end) totse,                   case when count(*)=0 7 else count(distinct rc) end totrc           eivtestitems ti, eivtests t            ti.test_id = t.test_id                   , t.test_type_id = 1                  , t.test_id=  '201405mase04'                  , ti.omit <> 1    ),     b     (           select cast('201405mase04' text) testid, count(*) totq           eivtestitems ti, eivtests t            ti.test_id = t.test_id                   , t.test_type_id = 1                  , t.test_id=  '201405mase04'                  , ti.omit = 1    ),    c    (           select cast('201405mase04' text) testid, count(*) totq           eivtestitems ti, eivtests t            ti.test_id = t.test_id                   , t.test_type_id = 1                  , t.test_id=  '201405mase04'                  , ti.question_type_id='2'    )     select a.testid, a.totq + coalesce(b.totq,0) - coalesce(c.totq,0) totq, a.totse, a.totrc       left outer join b on a.testid = b.testid    left outer join c on a.testid = c.testid 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -