I have a copy into table command that includes multiple dollar signs in the sql, all of which are escaped. If I print out the actual command from the script and execute it manually it works perfectly. But when the perl script does it I get a syntax error. This is what I'm trying to execute, the printout from the command and then the sql error in turn, (I have assigned a $file in the script where it is inserting the data so that dollar sign doesn't get escaped below)
my $sql = "COPY INTO metaproc.control_table FROM (
SELECT SPLIT_PART(METADATA\$FILENAME,'/',4) as SEAT_ID,
\$1:auction_id_64 as AUCTION_ID_64,
DATEADD(S,\$1:date_time,'1970-01-01') as DATE_TIME,
\$1:user_tz_offset as USER_TZ_OFFSET,
\$1:creative_width as CREATIVE_WIDTH,
\$1:creative_height as CREATIVE_HEIGHT
FROM \@DBNAME.lnd.S3_PROD_ADIP/$file)
pattern = '\.*\.parquet' file_format = (TYPE = 'PARQUET' SNAPPY_COMPRESSION = TRUE)
ON_ERROR = 'SKIP_FILE_10%';";
my $sth = $dbh->prepare($sql);
$sth->execute;
COPY INTO metaproc.control_table FROM (
SELECT SPLIT_PART(METADATA$FILENAME,'/',4) as SEAT_ID,
$1:auction_id_64 as AUCTION_ID_64,
DATEADD(S,$1:date_time,'1970-01-01') as DATE_TIME,
$1:user_tz_offset as USER_TZ_OFFSET,
$1:creative_width as CREATIVE_WIDTH,
$1:creative_height as CREATIVE_HEIGHT
FROM @DBNAME.lnd.S3_PROD_ADIP/pr/appnexus/data_dt=20220217/19/STANDARD_20220218012146.gz.parquet)
pattern = '.*.parquet' file_format = (TYPE = 'PARQUET' SNAPPY_COMPRESSION = TRUE)
ON_ERROR = 'SKIP_FILE_10%';
SQL compilation error: syntax error line 3 at position 4 unexpected '?'. syntax error line 4 at position 13 unexpected '?'. syntax error line 4 at position 13 unexpected '?'.
COPY INTO DWH_AIR.LND_APN.LND_STANDARD_IMP_EVENT FROM (
SELECT SPLIT_PART(METADATA$FILENAME,'/',4) as SEAT_ID,
$1? as AUCTION_ID_64,
DATEADD(S,$1?,'1970-01-01') as DATE_TIME,
$1? as USER_TZ_OFFSET,
$1? as CREATIVE_WIDTH,
$1? as CREATIVE_HEIGHT
line 3 position 4 is the question mark after the '$1' on the 3rd line. I don't get it, why is it removing the ':auction_id_64' part of the string?
CodePudding user response:
It looks like it is interpreting the : as a bind variable value, rather than a value in a variant. Have you tried using the bracket notation, instead?
https://docs.snowflake.com/en/user-guide/querying-semistructured.html#bracket-notation
I believe it would look something like
COPY INTO metaproc.control_table FROM (
SELECT SPLIT_PART(METADATA$FILENAME,'/',4) as SEAT_ID,
$1[auction_id_64] as AUCTION_ID_64,
DATEADD(S,$1[date_time],'1970-01-01') as DATE_TIME,
$1[user_tz_offset] as USER_TZ_OFFSET,
$1[creative_width] as CREATIVE_WIDTH,
$1[creative_height] as CREATIVE_HEIGHT
FROM @DBNAME.lnd.S3_PROD_ADIP/pr/appnexus/data_dt=20220217/19/STANDARD_20220218012146.gz.parquet)
pattern = '.*.parquet' file_format = (TYPE = 'PARQUET' SNAPPY_COMPRESSION = TRUE)
ON_ERROR = 'SKIP_FILE_10%';
I am uncertain whether this works or not, but if it doesn't, I will remove the answer.