How to check if a string is a number in flink sql - apache-flink

In flink sql, how to check whether a string is a number, as
select * from input where str like '\\d+'
the regular expression seems not useful, and the 'similar to' operator can't work either. Is there some idea?

Try defining a scalar function, here,
https://ci.apache.org/projects/flink/flink-docs-release-1.7/dev/table/udfs.html#scalar-functions

Related

About ms sql select

I'm not sure how to put it into words. I have this select in a ms sql table
select * from nomencl where Denumire='NGT2-65/201-32/1.3-72(DO) BMT 65 ,radial tool holder, DOOSAN'
and it returns nothing.
But if I use :
select * from nomencl where Denumire LIKE 'NGT2-65/201-32/1.3-72(DO) BMT 65 ,radial tool holder, DOOSAN%'
the record is there.
I'm not very skilled with ms sql, but I need to make it work. What could be the problem? Is it something in that string? I've searched for spaces at the end of the string but still found nothing.
It's because there is no row where Denumire equals 'NGT2-65/201-32/1.3-72(DO) BMT 65 ,radial tool holder, DOOSAN'. However, there is a row where Denumire starts with that value. The % on the end with LIKE denotes this.
LIKE is the ANSI/ISO standard operator for comparing a column value to another column value, or to a quoted string.
It returns either 1 (TRUE) or 0 (FALSE).
The equals to(=) operator is a comparison operator and used for equality test within two numbers or expressions.
LIKE is generally used only with strings however equals (=) is used for exact matching and it seems faster.

Use String parameter for RegEx in query

In my query (the database is a sql server) I use a RegEx for a select command like this:
SELECT * FROM test WHERE id LIKE '1[2,3]'
(This query is tested and returns the data I want)
I want to use a paramter for this RegEx. For that I definded the Paramter in iReport $P{id} as a string and the value is "1[2,3]".
In my query I use now this parameter like this:
SELECT * FROM test WHERE id LIKE $P{id}
As result I get a blank page. I think the problem is that the value of the parameter is defined with " ". But with ' ' I get a compiler error that the paramter isn't a string.
I hope someone can help me.
LIKE applies to text values, not to numeric values. Since id is numeric use something like this:
SELECT * FROM test WHERE id IN (12, 13)
with the parameter
SELECT * FROM test WHERE id IN ($P!{id_list})
and supply a comma separated list of ids for the parameter. The bang (!) makes sure that the parameter will be inserted as-is, without string delimiters.
Btw: LIKE (Transact-SQL) uses wildcards, not regex.
You can still use LIKE since there exists an implicit conversion from numeric types to text in T-SQL, but this will result in a (table or index) scan, where as the IN clause can take advantage of indexes.
The accepted answer works but it is using String replacement, read more about sql-injection, to understand why this is not good practice.
The correct way to execute this IN query in jasper report (using prepared statement) is:
SELECT * FROM test WHERE $X{IN, id, id_list}
For more information as the use of NOTIN, BETWEEN ecc. see JasperReports sample reference for query

Use of pipe symbol in Select clause

Is there any way/use of putting pipe symbol || in select clause.
I have come across following query in one of the article(probably to concatenate two values), but when I try to use the same in my query I am getting syntax error.
select FirstName ||''|| LastName As CustomerName from Customer
Please correct if I am using wrong syntax.
You can use CONCAT() function, which works in SQL Server 2012 and above, or just a plain + sign to do concatenation.
https://msdn.microsoft.com/en-us/library/hh231515(v=sql.110).aspx
Returns a string that is the result of concatenating two or more
string values.
you need to use '+' to perform Concat() instead of pipe if you are using SQL-Server. Pipe operator is not used in SQL-Server
It is used to concatenate you columns and output a single result i.e in one column.
For example, if i want to see first name and last name together as in one column then i could use pipes:
SELECT Fname||Lname FROM my_table;
If you are asking whether you can use pipes || for concatenation in Microsoft SQL, then the short answer is no.
If you’re asking about the concatenation operator itself, then read on.
|| is the standard ANSI concatenation operator. This is apparent in PostgreSQL, SQLite and Oracle, among others.
Microsoft, however uses +, because, why not. Except Microsoft Access uses &, because, why not.
MariaDB/MySQL have two modes. In traditional mode, || is interpreted as “or”, and there is no concatenation operator. In ANSI mode, || is interpreted as the concatenation operator.
Most DBMS (not SQLite) have the non-standard concat() function which will also concatenate. They also coalesce any NULLs to empty strings, so they’re a bit more forgiving if you don’t care about NULLs.

Set local variable in rdlc expression

Is it possible to somehow create variable in rdlc report expression in 'online' manner?
For example, I have following expression:
=IIf(First(Fields!BillingAccount_billtostateprovince.Value, "Invoice") <> "",
First(Fields!BillingAccount_billtostateprovince.Value, "Invoice") + " ",
"")
I suppose that I'm evaluating following expression First(Fields!BillingAccount_billtostateprovince.Value, "Invoice") twice. I don't like it and it looks ugly... I would prefer to create variable in the scope of current expression and use it.
Is it possible?
As user3056839 said, Welcome to SSRS!
Anyway, what you want is not possible since what you are writing right now is not a script but it's just an expression. It's a single statement that returns a value, so you cannot declare variables, use loops or anything that is part of a script.
You have to use exactly what you are writing.
Also it's not rare to see an IIF expression like yours. The one I constantly see is IFF( IS NOT NULL, , 'N/A'). The field may actually be evaluated twice, but there's nothing you can do. It's ugly but it's the only way you can do that.
Just think about the CASE WHEN clause:
SELECT
CASE WHEN MyField IS NOT NULL THEN
MyField ELSE 0
END
You are evaluating the field twice, but there's nothing you can do :)
It is possible to do it in SQL Server 2008 and above. You can create a Report Variable which can be accessed through out your report.
Reference: sqlchick.com

Regular expression in SQL Server 2005+

I am stuck with a regular expression in SQL server 2005+, i.e. I need a regular expression to validate a first name (which allows only alphabets,whitespaces and a .(dot)).
I tried with below query
SELECT PATINDEX('%[A-Z]%[a-z]%[.]%','John H. Wilson') as VALIDFIRSTNAME
But, this also fails in some cases. I'm unable to find a clear regular expression. Any assistance would be very much appreciated.
I have used patindex to recognise the given pattern. If the string doesn't match the pattern, then It should give 0 else it should give 1 or >1.
Thanks in advance.
You can't match mentioned condition with available patterns.
Try to follow this way.

Resources