Get single byte in clickhouse. Canno get very simple query work - yandex

The query SELECT splitByChar('x,y', ','); says
Received exception from server (version 1.1.54385): Code: 0.
DB::Exception: Received from localhost:9000, ::1. DB::Exception:
Illegal separator for function splitByChar. Must be exactly one byte.
What the hell does he want?

SELECT splitByChar(',', 'x,y');
Separator is the first argument.
Doc

Related

How to insert XML into SQL Server when it contains escaped invalid characters

I'm trying to insert some XML into a SQL Server database table which uses column type XML.
This works fine most of the time, but one user submitted some XML with the character with hex value 3, and SQL Server gave the error "hexadecimal value 0x03, is an invalid character."
Now I want to check, and remove, any invalid XML characters before doing the insert, and there are various articles suggesting how invalid XML characters can be replaced using regex or something similar.
However, the problem for me is that the user submitted the XML document with the invalid character escaped i.e. "", and none of the methods I've found will detect this. This is also why the error was not detected earlier: it's only when inserting it into the SQL database that the problem occurs.
Has anyone written a function that will check for all escaped invalid XML characters? I suppose the character above could have been written as  or , or lots of other ways, so it's quite hard to catch them all.
Thanks in advance for any help you can offer.
You could try importing the XML to a temporary varchar(max) variable or table column and use REPLACE to strip out the offending characters, then insert the cleansed string into the destination CASTing it to XML

Matching Regular Expressions In SQL Server

I am trying to extract id of Android app from its url but getting extra characters.
Using replace function in sql server, below are two sample urls:
https://play.google.com/store/apps/details?id=com.flipkart.android&hl=en com.flipkart.android
https://play.google.com/store/apps/details?hl=en_US&id=com.surveysampling.mobile.quickthoughts&referrer=mat_click_id%3Df1901cef59f79b1542d05a1fdfa67202-20150429-5128 en_US&id=com.surveysampling.mobile.quickthoughts&r
I am doing this right now:
SELECT
SUBSTRING(REPLACE(PREVIEW, '&hl=en',''), CHARINDEX('?', PREVIEW) + 4 , 50)
FROM OFFERS_TABLE;
But for 1st I am getting com.flipkart.android which is correct, but for 2nd I am getting en_US&id=com.surveysampling.mobile.quickthoughts&r.
I want to remove en_US&id from starting of it and &r from its end.
Can someone help me with any post or url from where I can refer?
What you are actually trying to do is extract the string preceded by id= until the & is found which is separator for variables in URL. Taking this condition I came up with following regex.
Regex: (?<=id=)[^&]*
Explanation: It uses the lookbehind assertion that is the string is preceded by id= until the first & is found.
Regex101 Demo
It seems like you've made some assumptions of lengths. The the &r is appearing because that is 50 characters. You are also getting the en_US because you assumed 4 characters at the beginning but your second string has more. Perhaps you can split on & and then look for the variable that begins with id=.
it seems like a function like this would help.
http://www.sqlservercentral.com/blogs/querying-microsoft-sql-server/2013/09/19/how-to-split-a-string-by-delimited-char-in-sql-server/

PhpStorm 10 strange database query execution warning

I started using PhpStorm 10 and I faced strange database query behaviour (Sybase IQ), namely I'm getting error:
[010P6] 010P6: A row was received and ignored. java.io.IOException: JZ0EM: End of data.
But query executes and I'm getting relevant result.
010P6 - A row was received and ignored.
Description: An unexpected object of type 0xD1 was encountered in the result set being processed and was ignored. Action: Check the query that generated the result set and correct as required.
Can somebody explain what should I correct? The only guess I have is that it comes long char data in the output.

Get TLD from email in mssql without tsql

Is there a simple solution to get the top level domain (TLD) from a e-mail address?
It's important, that TLDs like .berlin and Subdomains like info#infrastructure.bdata.de are also supported.
No TSQL, just one single query is possible.
Here's an example. Replace the example e-mail address with your real e-mail address:
Select substring( 'mike.meyer#infrastructure.bdata.berlin' , 1 + 1+ LEN('mike.meyer#infrastructure.bdata.berlin') - CHARINDEX('.' , reverse('mike.meyer#infrastructure.bdata.berlin')) , LEN('mike.meyer#infrastructure.bdata.berlin') )
The problem is, charindex() returns only the first character, but we need the last one. So we also need reverse().
The statement does the following steps:
Reverse the string and get the last .
Then we need substring. First parameter is the full string without reverse, second parameter is the start parameter. It's calcuated with the full length - length of the TLD. It's required to add +1 for the . and a second +1 for the start index of substring in mssql.
That's it!

Why is this data type conversion failing but not failing?

Ok, so I'm wracking my brain on this one...
These two queries... though they appear the same... are apparently different in some fashion. When run against a database in SQL Server Management Studio the top one results in an error (Conversion failed when converting from a character string to uniqueidentifier.) where as the bottom one runs just fine. Any ideas as to why that would be?
SELECT CONVERT(UNIQUEIDENTIFIER,'459B621C-A49A-49Cl-900F-AB14D61841E2');
SELECT CONVERT(UNIQUEIDENTIFIER,'459B621C-A49A-49C1-900F-AB14D61841E2');
Could it be a character encoding issue?
Thanks
There is a difference. The first one uses an l, the second is 1.

Resources