Alex Gordon
Alex Gordon

Reputation: 60841

How do we insert data into a table?

I'm attempting to insert data into a table:

@one_files = 
EXTRACT //all columns
FROM "/1_Main{suffixOne}.csv" 
USING Extractors.Text(delimiter : '|'); 

CREATE TABLE A1_Main (//all cols);

INSERT INTO A1_Main SELECT * FROM @one_files;

Within the same script I'm attempting to SELECT data:

@finalData = 
SELECT  //mycols
FROM A1_Main AS one;

OUTPUT @finalData
TO "/output/output.csv"
USING Outputters.Csv();

Here's the exception I get:

enter image description here

What am I doing wrong? How do I select from my table? Can we not insert and query in the same script?

Upvotes: 0

Views: 59

Answers (1)

Jorge Ribeiro
Jorge Ribeiro

Reputation: 1138

Some statements have restrictions on how they can be combined inside a script. For example, you cannot create a table and read from the same table in the same script, since the compiler requires that any input already physically exists at compile time of the query.

Check this:

https://learn.microsoft.com/en-us/u-sql/concepts/scripts

Upvotes: 1

Related Questions