I'm trying to concatenate two strings in Hive like below, but it keeps complaining about a ParseException
select concat('', cast(77 as varchar), '') as page_url
;
The message says:
FAILED: ParseException line 1:13 cannot recognize input near 'concat' '(' ''<a href="'' in expression specification
I tried using backticks around the strings and also escaping any potential special characters, but no luck. How can I get the concatenation to work?
I'm using Hive version 2.0.4
In this particular case, the problem was arising because I was using cast as varchar when I should have been using string
Related
I have a condition currently in presto like below
replace(replace(replace(replace(replace(replace(replace(replace(UPPER(FIELDNAME),' ',''),'LLC',''),'INC',''),'INTERNATIONAL',''),'LTD',''),'.',''),',',''),'QMT','')
What will be the equivalent function in Hive that will serve the exact same prurpose? Will regexp_replace work for the above scenario?
Used regexp_replace in the above condition instead of replace, but it is throwing me the below error.
FAILED: SemanticException [Error 10014]: Line 1:255 Wrong arguments ''('': No matching method for class org.apache.hadoop.hive.ql.udf.UDFRegExpReplace with (string, string). Possible choices: _FUNC_(string, string, string) (state=42000,code=10014)
It would be greatful if someone can help on this. Thanks
That is true. regexp_replace is the command that you can use. You can give the list of substrings to be substituted as a list separated by '|' and you need to use '\' to give any special characters which might act as wildcards like - . or ? or * etc. Below is the sample usage.
SELECT regexp_replace(upper(fieldname),'LTD|QMT|INTERNATIONAL|ORG|INC|\\.|,| ','') from my_table;
I am querying a database that uses Ingres 10.2. I cannot seem to get any of my pattern matching code to work as I expect it to.
For example:
SELECT TOP 20 *
FROM table_name
WHERE variable_name IN ('XaKDG', 'XaKDH')
returns both XaKDG and XaKDH as expected.
However, when trying this:
SELECT TOP 5 *
FROM table_name
WHERE variable_name LIKE 'XaKD\[GH\]' escape '\'
I get the following errors:
ERROR '22025' 1315172
Illegal pattern match specified
Illegal ESCAPE sequence.
I am baffled, as the user guide states the following:
"To match any string starting with 0 through 4, followed by an uppercase letter, then a [, any two characters and a final ]:"
name like '\[01234\]\[A-Z\][__]' escape '\'
As far as I can tell, my query should be correct. I also tried without the escape characters at all, and with double escape characters. These didn't produce any errors, but also did not return anything.
I appreciate any help.
The User guide is here: https://supportactian.secure.force.com/help/servlet/fileField?id=0BEf3000000PLPf
I am getting a syntax error in a PostgreSQL query. I am working on a project developed in YII1, I am getting an error
CDbCommand failed to execute the SQL statement: SQLSTATE[42601]:
Syntax error: 7 ERROR: syntax error at or near "s" LINE 1: ...OT NULL
AND sub_heading like '%Women and Children's Voices%'.
As you can see above, I am using the like operator in single quotes, and in the string there is another single quote (Children's). So PostgreSQL is throwing me an error. Please provide me a solution to escape the string.
You can escape a single quote in a string by using another single quote (i.e., '' instead of '. Note that these are two ' characters, not a single " character):
sub_heading LIKE '%Women and Children''s Voices%'
-- Here -----------------------------^
You should use the format function to construct the SQL statement, using the %L placeholder for the pattern.
I solved this problem by replacing the single quote with double quotes using PHP. Here is the code
There is a variable $var with value Women and Children's Voices. I replace that single quote using the str_replace() function.
$var = str_replace("'", "''", $var);
Select * from mytable where field=
'ce7bd3d4-dbdd-407e-a3c3-ce093a65abc9;cdb597073;7cf6cda5fc'
Getting Below Error while running above query in Hive
FAILED: ParseException line 1:92 character '' not supported here
<EOF> here means End Of File. When you get an "unexpected End Of File" error it means the parser reached the end of the query unexpectedly. This typically happens when the parser is expecting to find a closing character, such as when you have started a string with ' or " but have not closed the string (with the closing ' or ").
When you come across these types of errors it is good to check that your query can be parsed correctly. In addition, the error gives you the location where the parser failed: line 1:92 in this case. You can usually look at this location (character 92 of the query) and work backwards to find the problem character.
Try adding the database name to the "from" statement as below.
Select * from my_db_name.mytable where field= 'ce7bd3d4-dbdd-407e-a3c3-
ce093a65abc9;cdb597073;7cf6cda5fc';
Hive uses the default database when no database was previously specified.
I'm trying to use REGEXP_REPLACE to remove all punctuation from a varchar. I'm using the following:
regexp_replace(d.NAME, [.,\/#!$%\^&\*;:{}=\-_`~()])
But it gives me an error, saying:
Statement 1 is not valid. ERROR: syntax error at or near "."
How can I fix this to remove all punctuation?
Firstly, the dash in a character class means a range, except when it's first or last... so put it there:
[.,\/#!$%\^&\*;:{}=\_`~()-]
And, you have to put it in quotes, and most characters don't need escaping:
regexp_replace(d.NAME, '[.,/#!$%^&*;:{}=_`~()-]')