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:

                                 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?


2 Answers 2


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...

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)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.