Database Administrators Asked on October 27, 2021
I am running a query from SQL Server 2019(64bit) SSMS to PostgreSQL on AWS through Linked Server. Other queries are working fine but this particular query is failing due to message column. My query is as follows:
SELECT * from OPENQUERY (ABC, 'SELECT id,
old_message,
message
FROM actions;')
Error Message:
OLE DB provider ‘MSDASQL’ for linked server ‘DRIQ’ returned data that does not match expected data length for column ‘[MSDASQL].message’. The (maximum) expected data length is 1400, while the returned data length is 1510.
Query is working fine without message column. But when I add message column, it start giving me an above error. The datatype of message column is JSON in postgres db. For ODBC, I am using 64bit Unicode(x64) and compatibility level of my db is 150. So how to get the data of message(json) column in sql server 2019?
It seems PostgreSQL is sending more data than SQL Server is expecting. I'd be trying to use a PostgreSQL function to convert the data column to something wider (i.e. the equivalent of Cast or Convert) so that SQL Server doesn't choke on the returned data.
Does it work if you cast it as text
? e.g. message::text
Or maybe a large varchar? message::varchar(8000)
?
Answered by user229088 on October 27, 2021
Try with a different driver?
SQL Server and PostgreSQL Linked Server Configuration
You might also want to try implicitly casting the columns to tsql datatypes, i.e.
SELECT CAST(Id AS INT) AS Id, CAST(old_message AS NVARCHAR(MAX)) AS old_message, CAST(message AS NVARCHAR(MAX)) AS message FROM OPENQUERY...
Answered by user213692 on October 27, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP