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

Bradley Schacht

Bradley Schacht is a Data Platform Solution Architect on the state and local government team with Microsoft based in Jacksonville, FL. He has co-authored 3 SQL Server books including "SQL Server 2014 Professional Admin". As a former consultant and trainer, he uses his experience on many parts of the Microsoft BI and data platform to help customers deliver the best possible solutions. Bradley frequently presents at community events around the country. He is a contributor to sites such as SQLServerCentral.com and an active member of the Jacksonville SQL Server User Group (JSSUG).

Converting SQL_VARIANT on PDW

There are a number of data types that are currently unsupported on PDW. Among those are SQL_VARIANT. The interesting part of that is that SQL_VARIANT along with several other unsupported data types are found all over the place in system tables in PDW. There is a simple solution, convert the value to something like VARCHAR. Well this wouldn’t be a blog post if that was all I had to say on the matter.

Turns out that you can select the data just fine, convert it in a select just fine, but for some odd reason not do an insert with it just fine. Let’s take the partitions range table for this example.

SELECT
CONVERT(VARCHAR(200), value, 101) AS ConvertedText
FROM sys.partition_range_values

Try to insert that into a temp table and bad things happen.

--Create a temp table
CREATE TABLE #Partitions
(
Value VARCHAR(200)
)
WITH (LOCATION = USER_DB)

--Load the temp table
INSERT INTO #Partitions
SELECT
CONVERT(VARCHAR(200), value, 101) AS ConvertedText
FROM sys.partition_range_values

--Select the records
SELECT * FROM #Partitions

--Drop the table
DROP TABLE #Partitions

You will get this error when it runs the insert statement even though it is clearly being converted.

Error!

Msg 100077, Level 16, State 1, Line 1

Unsupported data type error. Statement references a data type that is unsupported in Parallel Data Warehouse, or there is an expression that yields an unsupported data type. Modify the statement and re-execute it.

The workaround: CTAS works like a charm!

CREATE TABLE TestPartition
WITH (DISTRIBUTION = REPLICATE) AS
SELECT
CONVERT(VARCHAR(200), value, 101) AS ConvertedText
FROM sys.partition_range_values

SELECT * FROM TestPartition

DROP TABLE TestPartition

For those who require visual proof:

CTAS_Partitions

Happy CTASing and happy Friday!

 

Comments

Leave a comment on the original post [www.bradleyschacht.com, opens in a new window]

Loading comments...