Converting SQL Server varbinary to PostgreSQL Bytea



Converting SQL Server varbinary to PostgreSQL Bytea

Converting SQL Server varbinary to PostgreSQL Bytea

Converting SQL Server varbinary tp PostgreSQL bytea datatype can be achieved by using master.dbo.fn_varbintohexstr.
First two character need to be removed as Sql server add those character to make hexadecimal identifiable. Below is script used for datatype conversion:
SQL Server script:
select cast(cast(‘hello world’ as varbinary) as varchar(max))

select master.dbo.fn_varbintohexstr(cast(‘hello world’ as varbinary))

select substring( t.ConvertedText, 3, len(t.convertedText)) from (select 1 as ID) r
cross apply
(
select master.dbo.fn_varbintohexstr(cast(‘hello world’ as varbinary)) [ConvertedText]
)t

PostgreSQL script:
select encode(decode(‘68656c6c6f20776f726c64’, ‘hex’), ‘escape’)

Comments are closed.