The ~ character is showing compilation error in snowflake - amazon-redshift

unexpected '~'
When trying to migrate queries from red shift to snowflake, i keep on getting unexpected '~'.
Please help
case when tablename.fieldname ~'..'then .. else ..

From what I can tell the ~ operator is Postgres specific. It is not a standard SQL operator.
If you're trying to use regex here's some general documentation https://docs.snowflake.com/en/sql-reference/functions-regexp.html
Or perhaps the LIKE/RLIKE functions
https://docs.snowflake.com/en/sql-reference/functions/rlike.html
If that's not what you're after, or I'm misunderstanding, can you provide more code, your expected results, and the full error message?

Related

mitmdump replacement pattern construction

I'm trying to specify replacements in mitmdump but am having trouble getting the syntax right. What I want to do is replace the entire path in a request with a fixed string.
I've tried -R :~bq:/*:/example.html but that results in "Invalid filter pattern: ~bq"
Any pointers?
Try to use ~q not ~bq as filter pattern. Because ~bq needs regex itself like ~bq regex. The error "Invalid filter pattern" is caused by using ~bq with regex part.
More details https://github.com/mitmproxy/mitmproxy/pull/2589#issuecomment-340426254

When I run a file which is begin with "#!/usr/bin/perl -w", I get a error: "syntax error at line 153, near "=~ ?""

When I run a file which is begin with #!/usr/bin/perl -w, I get a error:
syntax error at line 153, near "=~ ?"
I try to add "#!/bin/bash", this error is not append, but I get another
error:
"line 34: syntax error near unexpected token `('"
line 153 in my file:
($output_volume =~ ?^([\S]+).mnc?) && ($base_name = $1) ||
die "sharpen_volume failed: output volume does not appear to be"
." a minc volume.\n";
line34 in my file:
use MNI::Startup qw(nocputimes);
$output_volume =~ ?^([\S]+).mnc?
This used to be valid perl and thus might appear in old code and instructional material.
From perlop:
In the past, the leading m in m?PATTERN? was optional, but omitting it would produce a deprecation warning. As of v5.22.0, omitting it produces a syntax error. If you encounter this construct in older code, you can just add m.
That is Perl code so the first error message is meaningful.
With delimiters other than // in the match operator you must have the explicit m for it, so
$output_volume =~ m?^([\S]+).mnc?
It is only with // delimiters that the m may be omitted; from Regex Quote-Like Operators (perlop)
If "/" is the delimiter then the initial m is optional.
See perlretut for a tutorial introduction to regex and perlre for reference.
Also note that the particular delimiters of ? trigger specific regex behavior in a special case. This is discussed by the end of the documentation section in perlop linked above.
You already have two answers that explain the problem.
? ... ? is no longer valid syntax for a match operator. You need m? ... ? instead.
Until Perl 5.22, your syntax generated a warning. Now it's a fatal error (which is what you are seeing). So I assume you're now running this on a more recent version of Perl.
There are, however, a few other points it is probably worth making.
You say you tried to investigate this by changing the first line of your file from #!/usr/bin/perl -w to #!/bin/bash. I'm not sure how you think this was going to help. This line defines the program that is used to run your code. As you have Perl code, you need to run it with Perl. Trying to run it with bash is very unlikely to be useful.
The m? ... ? (or, formerly, ? ... ?) syntax triggers an obscure and specialised behaviour. It seems to me that this behaviour isn't required in your case, so you can probably change it to the more usual / ... /.
Your regex contains an unescaped dot character. Given that you seem to be extracting the basename from a filename that has an extension, it seems likely that this should be escaped (using \.) so that it matches an actual dot (rather than any character).
If you are using this code to extract a file's basename, then using a regex probably isn't the best approach. Perhaps take a look at File::Basename instead.

Is there a way to have Postgres tell you what a syntax error was in addition to what it is at/near?

I've tried setting 'log_min_error_statement' equal to debug5 in postgresql.conf but I'm still getting the standard "PostgreSQL said: syntax error at or near "AS"" error message in both the console and the postgresql log.
If PostgreSQL knew what the error was it'd tell you, at least in most cases.
If it just says "Syntax error at or near ..." it doesn't know what you meant, and can't guess what's wrong. It's a parse error. It could offer a (very long) list of suggestions, but that'd make error messages absurdly verbose, like:
postgres=# SELECT AS fred ORDER BY 1;
ERROR: syntax error at or near "AS"
LINE 1: SELECT AS fred ORDER BY 1;
Yup, that's a syntax error, because it doesn't make sense on any level. What's wrong with it? How do you succinctly describe that? How does a parser even tell what's wrong?
postgres=# SELECT AS fred ORDER BY 1;
ERROR: syntax error at or near "AS"
LINE 1: SELECT AS fred ORDER BY 1;
HINT: typo?
HINT: Did you use a reserved keyword as an identifier without "quoting" it? Like "AS"?
HINT: Did you leave out the value before the AS keyword?
HINT: ... endless possibilities ...
Occasionally a parser can guess something you might've done wrong. PostgreSQL's parser tries to tell you when it can, e.g.
psql -c "SELECT 'openquote";
ERROR: unterminated quoted string at or near "'openquote"
LINE 1: SELECT 'openquote

Using Github API code search, find the exact string `throw "`

I want to find the exact strings, throw ' and throw " in javascript files in a given repo using the Github API.
It says:
You can't use the following wildcard characters as part of your search
query: . , : ; / \ ` ' " = * ! ? # $ & + ^ | ~ < > ( ) { } [ ]. The
search will simply ignore these symbols.
I'm supposing there is no way to find these exact strings using the API?
I have tried various searches with no luck. Trying to escape the " with \ doesn't work either.
https://api.github.com/search/code?q=%22throw+%27%22+in:file+language:js+repo:angular/angular.js
All of the queries I try return, for instance, https://github.com/angular/angular.js/blob/master/docs/config/tag-defs/tutorial-step.js which just finds the throw and disregards the '.
An alternative to this strategy is to find where there is NOT Error on the line, so that the search is throw NOT Error to try to find where someone is throwing a string and not throw new Error(. This strategy doesn't work for some reason. For instance,
https://api.github.com/search/code?q=%22throw%20NOT%20Error%22+in:file+language:js+repo:driverdan/node-XMLHttpRequest
There are many times that a plain string is thrown in https://github.com/driverdan/node-XMLHttpRequest/blob/master/lib/XMLHttpRequest.js but, the file does contain the string Error; so, I guess this is enough to make the result empty. I'm seeing a way to "search" in my client program as a workaround; but, I would rather get the results from the API.
I'm supposing there is no way to find these exact strings using the API?
Correct, that's not possible currently.

Postgres / SQL::Abstract "Not In Range" Operation

Postgres has some cool range operators for handling ranges:
http://www.postgresql.org/docs/devel/static/functions-range.html
...but doesn't appear to have anything to handle 'not' being in a range. For instance, the #> operator means 'contains element' or 'contains range'. But equally helpful would be the !#> operator, which doesn't seem to exist.
If I'm trying to say "query where date is not in range", is there any solution other than using a conditional expression? I'm using SQL::Abstract, which doesn't support expressions without using literal SQL, which I would like to avoid.
I do it this way
FALSE = INT4RANGE(1,5) #> 5
I would recommend using NOT BETWEEN date AND date.
Sorry, you may still end up using a SQL literal.