I'm looking for some assistance in debugging a REGEXP_REPLACE() statement.
I have been using an online regular expressions editor to build expressions, and then the SF regexp_* functions to implement them. I've attempted to remain consistent with the SF regex implementation, but I'm seeing an inconsistency in the returned results that I'm hoping someone can explain :)
My intent is to replace commas within the text (excluding commas with double-quoted text) with a new delimiter (#^#).
Sample text string:
"Foreign Corporate Name Registration","99999","Valuation Research",,"Active Name",02/09/2020,"02/09/2020","NEVADA","UNITED STATES",,,"123 SOME STREET",,"MILWAUKEE","WI","53202","UNITED STATES","123 SOME STREET",,"MILWAUKEE","WI","53202","UNITED STATES",,,,,,,,,,,,
RegEx command and Substitution (working in regex101.com):
([("].*?["])*?(,)
\1#^#
regex101.com Result:
"Foreign Corporate Name Registration"#^#"99999"#^#"Valuation Research"#^##^#"Active Name"#^#02/09/2020#^#"02/09/2020"#^#"NEVADA"#^#"UNITED STATES"#^##^##^#"123 SOME STREET"#^##^#"MILWAUKEE"#^#"WI"#^#"53202"#^#"UNITED STATES"#^#"123 SOME STREET"#^##^#"MILWAUKEE"#^#"WI"#^#"53202"#^#"UNITED STATES"#^##^##^##^##^##^##^##^##^##^##^##^#
When I try and implement this same logic in SF using REGEXP_REPLACE(), I am using the following statement:
SELECT TOP 500
A.C1
,REGEXP_REPLACE((A."C1"),'([("].*?["])*?(,)','\\1#^#') AS BASE
FROM
"<Warehouse>"."<database>"."<table>" AS A
This statement returns the result for BASE:
"Foreign Corporate Name Registration","99999","Valuation Research",,"Active Name",02/09/2020,"02/09/2020","NEVADA","UNITED STATES",,,"123 SOME STREET",,"MILWAUKEE","WI","53202","UNITED STATES","123 SOME STREET",,"MILWAUKEE","WI","53202","UNITED STATES"#^##^##^##^##^##^##^##^##^##^##^##^#
As you can see when comparing the results, the SF result set is only replacing commas at the tail-end of the text.
Can anyone tell me why the results between regex101.com and SF are returning different results with the same statement? Is my expression non-compliant with the SF implementation of RegEx - and if yes, can you tell me why?
Many many thanks for your time and effort reading this far!
Happy Wednesday,
Casey.
The use of .*? to achieve lazy matching for regexing is limited to PCRE, which Snowflake does not support. To see this, in regex101.com, change your 'flavor" to be anything other than PCRE (PHP); you will see that your ([("].*?["])*?(,) regex no longer achieves what you are expecting.
I believe that this will work for your purposes:
REGEXP_REPLACE(A.C1,'("[^"]*")*,','\\1#^#')
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
I use UPDATE a SET GR_P = REPLACE(GR_P,'','') FROM mytable a to replace things.
But replace function is not working for below charter:
In Query analyzer it works but when I used SSIS Execute SQL task or OLEDB Source then it is giving me error:
No Connection manager is specified.
In Toad against Oracle (since that's one of your tags), I issued this (pressing ALT-12 to get the female symbol) and got 191 as a result. note selecting it back using CHR(191) shows an upside-down question mark though.
select ascii('♀') from dual;
Given that, this worked but it's Oracle syntax, your mileage may vary.
UPDATE mytable SET GR_P = REPLACE(GR_P, CHR(191));
Note if it does not work, that symbol could be for another control character. You may need to use a regular expression to eliminate all characters not in a-zA-Z0-9, etc. I suspect you'll need to update your tags to get a more accurate answer.
Maybe this info will help anyway. Please post back what you find out.
I am transforming the following informatica code to SQL. I am encountering some issues and would appreciate help with the following code:
SUBSTR(COV_REINS_CONCAT_BK,INSTR(COV_REINS_CONCAT_BK,'|',1,3) +1,2)
That is, I am looking for the equivalent code to produce the same results in SQL Server.
I appreciate anyone's help!
SUBSTR's equivalent is SUBSTRING.
INSTR's equivalent is CHARINDEX, but it has the first 2 parameters reversed, and does not support the 4th parameter (occurrence).
The expression returns 2 characters after the third occurrence of | (pipe).
Example: It will return 'FG' for 'A|BC|DE|FGH'.
So the translation will be:
SUBSTRING(COV_REINS_CONCAT_BK,1+CHARINDEX('|',COV_REINS_CONCAT_BK,1+CHARINDEX('|'
,COV_REINS_CONCAT_BK,1+CHARINDEX('|',COV_REINS_CONCAT_BK))),2)
I have some MathML that contains tags that identify various function calls (though this scenario can apply to any XML).
A sample would be:
<math>
<apply>
<ci>IIF</ci>
<apply>
<eq />
<apply>
<ci>DDOutputB60</ci>
<ci>Index</ci>
</apply>
<cn>0</cn>
</apply>
<cn>0</cn>
<apply>
<ci>DDOutputB60</ci>
<ci>Index</ci>
</apply>
</apply>
</math>
As you can see, this particular sample identifies two function calls - but both are to the same function (DDOutputB60)
I am attempting to write some SQL to list the DISTINCT functions but need to do this in the XPath and not in a wrapper SELECT statement that selects DISTINCT from the result set.
(As an aside, the reason for this is that this is the member SQL for a recursive CTE and DISTINCT or GROUP BY are not allowed)
I am led to believe that the following is valid XPath that will select distinct values but is not supported in SQL Server 2008:
COLUMN.nodes('(//ci[not(text() = preceding-sibling::ci/text())])')
Can anyone suggest an XPath equivalent that will work in SQL Server 2008?
Perhaps the >> or << node comparison operators might help, but I'm not an expert. Yet.
Thanks in advance.
#Ravi: the desired output would be the result of the .nodes(...) sql function which I assume would look in this case like:
<ci>DDOutputB60</ci>
It would be a single node result as the duplicate has been removed.
Perhaps the >> or << node comparison operators might help, but I'm not an expert. Yet.
Yes this is what you need
Here example in those two answer:
Getting the following sibling in an XPath when “following” axis is not supported
Get followin sibling in SQL Server XPath