Share via

Parse error in Synapse COPY command

Vimal Sivaraman 41 Reputation points
2021-10-28T08:29:21.753+00:00

Hi,

I'm trying to bulk load csv data to Synapse table using COPY. For that I'm using a procedure call and trying to pass the KEY as a variable from python. While doing so, I'm facing parse error as given below.

ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Parse error at line: 2, column: 91: Incorrect syntax near 'XXXXXXXXXXXTbXXuXXXXXXXXXXXXr1XXXXXXXXXXXXP'. (103010) (SQLExecDirectW)")

Procedure Body

-----------------

GO
CREATE PROC [SCHE].[PROC_COPY_DATA] @KeyVal VARCHAR AS
BEGIN
DECLARE @alenzi VARCHAR(500);
SET @alenzi = 'COPY INTO SCHE.TABLETEST FROM ''https://tempaccount.blob.core.windows.net/tempaccount/uploadfile.csv''
WITH (FILE_TYPE = ''CSV'', CREDENTIAL=(IDENTITY= ''Storage Account Key'', SECRET= '+ @KeyVal + '), FIELDTERMINATOR = '','', FIRSTROW = 2);'
EXEC (@alenzi )

END;

KeyVal = XXXXXXXXXXXTbXXuXXXXXXXXXXXXr1XXXXXXXXXXXXP+i/XXXX/XWXW2XWXWXWFGG8s2w==

While trying to run directly from Data Studio I'm getting same parse error.

Command tried from Data Studio.

---------------------------------------

exec DTAPO.PROC_COPY_DATA N'XXXXXXXXXXXTbXXuXXXXXXXXXXXXr1XXXXXXXXXXXXP+i/XXXX/XWXW2XWXWXWFGG8s2w=='

Msg 103010, Level 16, State 1, Line 1
Parse error at line: 2, column: 91: Incorrect syntax near 'XXXXXXXXXXXTbXXuXXXXXXXXXXXXr1XXXXXXXXXXXXP'.

It seems like from literal +, it is terminating the string and hence failing.

If someone knows any sort of workaround for this, Please suggest!.

Thank You.

Azure Synapse Analytics
Azure Synapse Analytics

An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.

0 comments No comments

Answer accepted by question author

HimanshuSinha 19,637 Reputation points Microsoft Employee Moderator
2021-10-28T21:11:09.107+00:00

Hello @ADX ,
Thanks for the ask and using Microsoft Q&A platform .

I have replied to something similar here . https://stackoverflow.com/questions/65833908/syntax-error-when-using-input-parameter-to-create-procedure/65895040#65895040

Adding the comment here for completedness .

This should work . I have created the Copy command dynamically and passing the SAS token to that . Once I have the copy command created I execute the command . The print statement , i used it as a test

CREATE PROCEDURE dbo.bulk_load
anonymous user_token VARCHAR(500)
AS
BEGIN
--DECLARE anonymous user varchar(500)
--SET anonymous user = ''''+ anonymous user_token + ''''
declare @Query varchar(max)
IF OBJECT_ID('dbo.ITEM_INFORMATION') IS NOT NULL
DROP TABLE dbo.ITEM_INFORMATION

;

CREATE TABLE dbo.ITEM_INFORMATION   
(  
    SSN VARCHAR(20),  
    Name VARCHAR(15)  
);  

SELECT @query  ='  
COPY INTO dbo.ITEM_INFORMATION  
FROM ''https://server.blob.core.windows.net/container/subfolder/file.csv''  
     WITH (FILE_TYPE = ''CSV'',  
           FIELDTERMINATOR = ''',''',  
           FIRSTROW = 2,  
           ROWTERMINATOR = ''\n'',  
           CREDENTIAL = (  
                         IDENTITY = ''Shared Access Signature'',  
                         SECRET =  '''+*anonymous user*_token+'''  
                         )  
        );'  
        print @query  
        exec(@query)  

END

Please do let me know how it goes .
Thanks
Himanshu

-------------------------------------------------------------------------------------------------------------------------

  • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how
  • Want a reminder to come back and check responses? Here is how to subscribe to a notification
  • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators

Was this answer helpful?

2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.