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?
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.
Related
UPDATE ASSIGNMENTS SET CBTURL = REPLACE(CBTURL, 'http://172.21.130.19/', 'https://testlpsweb.corp.mbll.ca/Content/')
The above statement produces "Data truncation" error. Please advise why and how to correct it.
Error starting at line : 1 in command - UPDATE ASSIGNMENTS SET CBTURL = REPLACE(CBTURL, 'http://172.21.130.19/', 'https://testlpsweb.corp.mbll.ca/Content/') Error at Command Line : 1 Column : 1 Error report - SQL Error: Data truncation
I'm guessing that CBTURL column length is to small for resulting string of replace. Could you try to alter column to have larger lenght.
Try this query to see maximum resulst string lenght:
Select Max(Len(REPLACE(CBTURL, 'http://172.21.130.19/', 'https://testlpsweb.corp.mbll.ca/Content/'))) from tablename ....
Getting the following error when copying an input file into an empty db table. The input file only has 56732 rows, however I am getting an error on row 56733:
continue
* * * * * * * * * *
copy table temptable
(
abc = c(3),
bcao = c(1),
cba = c(10),
test = c(1)nl
)
from 'tempfile'
Executing . . .
E_CO0024 COPY: Unexpected END OF FILE while processing row 56733.
E_CO002A COPY: Copy has been aborted.
Anyone have any ideas why its trying to process an extra row? I have four other files the exact same format with different data and it processes fine.
Have no idea why this is happening...
The most likely cause is that you have some spaces or similar after your final row of data. You have set a new line as a delimiter on test, so the file needs to end with a new line. Delete anything after your data which isn't a blank new line.
As an example. Using the code below:
DECLARE GLOBAL TEMPORARY TABLE test (
v int
) ON COMMIT PRESERVE ROWS WITH NORECOVERY;
COPY test (
v = c(5)nl
) FROM 'J:\test.csv';
Will result in an error on line 4 for the following data:
34565
37457
35764
45685
and error on line 5 for this data (punctuation used to show issue, but it is probably a space or tab in your own file):
34565
37457
35764
45685
.
I am trying to run perl script but i get an oracle error.
DBD::Oracle::db prepare failed: ORA-01756: quoted string not properly terminated (DBD ERROR: OCIStmtPrepare)
But this SQL QUERY perfectly works fine in TOAD
MY perl connection details:
my $dbh = DBI->connect($dsn, $dbuser, $dbpass, { RaiseError => 1, AutoCommit => 0 });
my $sth=$dbh->prepare($SQL);
$sth->execute or die "EXEC ERROR $sth->errstr";
sql query:
SELECT name FROM employee WHERE
event IN ('IPO', 'RIGHTS')
AND (NOT market_code = 'ID' OR NOT event = 'RIGHTS')
AND NOT market_code = 'IN'
AND NOT market_code = 'NZ'
AND name NOT LIKE '%stat%'
AND NOT REGEXP_LIKE (name, 'S.K(Q|S)$')
AND name NOT LIKE '.%'
AND name NOT LIKE '%ol.SI'
AND name NOT LIKE '%bi.SI'
Perl will interpolate double-quoted string literals, like
my $SQL = "REGEXP_LIKE (name, 'S.K(Q|S)$')";
In here, your "variable" $' will be replaced with its value.
If you don't want that, use a non-interpolating version:
my $SQL = q{REGEXP_LIKE (name, 'S.K(Q|S)$')};
Single-quoted strings would also do, but since you have single quotes inside, the q{} is convenient. You can choose any terminator you want (such as q[]) and you can make it interpolate, too, with qq{}.
To start, I had this error:
Error parsing data org.json.JSONException: Value You of type java.lang.String cannot be converted to JSONObject
After some searching, I found a potential solution using substring to see if there were just some phantom characters causing an issue: 'json.substring(3)'
After trying different substring amounts, I got to json.substring(36) and it finally showed me more than 5 letters at a time:
Error parsing data org.json.JSONException: Expected literal value at character 0 of ; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND from_user = 277976949048048 AND (status = 'pending' OR status = 'accepted'))' at line 2
Maybe this new 'expected literal' thing is caused by doing the substring 36, but either way, it seems like there is an issue with my SQL syntax even though I tested it directly with the server and it works perfectly. here is my sql query.
$result = mysql_query("SELECT status FROM users join requests on users.facebook_id=requests.from_user
WHERE (to_user = $id AND from_user = $fbid AND (status = 'pending' OR status = 'accepted'))
OR (from_user = $id AND to_user = $fbid AND (status = 'pending' OR status = 'accepted'))
LIMIT 1") or die(mysql_error());
Any help much appreciated because now I'm officially stumped.
I had some issues in the past with parsing JSON files including huge integer numbers.
The number 277976949048048 seems too large to be treated as an integer, I would suggest treating it as a string.
$q = 'INSERT INTO MyTable(proddesc, qnty, PriceH, PriceA, PriceL) VALUES(?,?,?,?,?)';
$sth = odbc_prepare($dbConn, $q);
$success = odbc_execute($sth, array(my 5 variables that are not null));
It gives me the above error - [ODBC Microsoft Access Driver] COUNT field incorrect. I know that the query is correct because I ran it in Access and it was fine. I think I may be using the prepare/execute statements incorrectly.
I also encountered this now and the solution I did to fix it is to quote the variables properly.
Try printing your $q and you will see if it needs to be quoted.
You can try these too:
INSERT INTO TABLE -- quote db and table names using (`) "grave accent" character
VALUES( 'Fed''s' ) -- quote the apostrophes