Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


OpenQuery to Postgres Error on text field


OpenQuery to Postgres Error on text field

Author
Message
cenko
cenko
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 42

I am getting the error below when executing the following query to extract data from a linked server (CORE_ODBC) to Postgres. The column "Text" is of text datatype. The values in the column can be over 1MB in size. I’ve increased the length for casting the "Text" column but still get the same error. Any thoughts on how to handle this? style="FONT-SIZE: 13px; COLOR: rgb(0,0,255); FONT-FAMILY: Courier New"> >

Select * From Openquery(CORE_ODBC, 'Select "TCKT_MessageID", "CONT_ContactID", "Date", cast("Text" as varchar(4000)), "Private", "TCKT_val_SourceID", "SourceContact", "SentToCustomer", "UnusedColumn", "PrivatizeContact", "DatePrivatized", "TCKT_TicketID", cast("creation_date" as varchar(30)), cast("modification_date" as varchar(30)) From "TCKT_Message" ') style="FONT-SIZE: 13px; COLOR: rgb(128,128,128); FONT-FAMILY: Courier New">>

Msg 7347, Level 16, State 1, Line 1 style="FONT-SIZE: 10px; FONT-FAMILY: Courier New">>

OLE DB provider 'MSDASQL' for linked server 'CORE_ODBC' returned data that does not match expected data length for column '[MSDASQL].Text'. The (maximum) expected data length is 8000, while the returned data length is 8318. style="FONT-SIZE: 10px; FONT-FAMILY: Courier New">>


Site Owners
Site Owners
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10095 Visits: 1
No one has responded to this topic yet. Even if you don't have a complete answer, the original poster will appreciate any thoughts you have!
rrv
rrv
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 60
may be you need to increase the max varchar size in the postgres driver

and

change the code to

substr("Text",1,4000)
jgrubb
jgrubb
Old Hand
Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)Old Hand (302 reputation)

Group: General Forum Members
Points: 302 Visits: 567
You've a datatype problem here. You'll need need to explicitly trim the results to be less than 8000 bytes. Postgres text is similar to MSSQL text. Postgres varchar (or character varying) is not similar to MSSQL varchar. It can be bigger. Postgres implicit casts do not always work like you expect.

If you explore the resultset return types, betcha you're getting something unexpected.
Linda Johanning
Linda Johanning
Old Hand
Old Hand (333 reputation)Old Hand (333 reputation)Old Hand (333 reputation)Old Hand (333 reputation)Old Hand (333 reputation)Old Hand (333 reputation)Old Hand (333 reputation)Old Hand (333 reputation)

Group: General Forum Members
Points: 333 Visits: 620
I agree that there is a datatype issue as I am trying to do the same thing. I was stuck on a PostgreSQL BPCHAR datatype and got the same error as you did (using openquery and also the 4-part name) however, I stumbled on this and it seems to work:

declare @sql nvarchar(2000)
Set @sql = 'select * from schema.table'
exec (@sql) At LinkedServerName

This query usually shows a better explanation of a PostgreSQL error, but when I run it against this particular table the data is returned. For me the column in question contains Y, N or Null. Interesting. I hope this works for you.



GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47415 Visits: 44402
Please note: 6 year old thread.


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


TomThomson
TomThomson
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10769 Visits: 12019
GilaMonster (7/9/2013)
Please note: 6 year old thread.

But note that the site owners pushed it after it had gone unanswered for 5 days more than a year - which should make us ask ourselves how old does something have to be before it is old?

Tom

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search