how to find max date and hour everyday by using hive query - hiveql

I am getting error as org.apache.hive.service.cli.HiveSQLException:
Error while compiling statement: FAILED: ParseException line 1:168 cannot recognize input near 'select' 'max' '(' in expression specification while using max(date) and max(sum_hour)

If I interpret correctly, you can do:
select max(datecol)
from t
group by year(datecol), month(datecol), day(datecol);

date is a reserved word.
Use `date` or even better, rename your column

Related

to_char function hexadecimal formats error in Postgresql

I want to use to_char function in Postgresql but take an error when execute the script.
Oracle version is ok;
to_char('7374961057827412212','XXXXXXXXXXXXXXXXXXXX')
result : 66592002042458F4
But I could not find Postgresql version and take an error like this;
ERROR: function to_char(text, unknown) does not exist
If you look at the table of formatting codes for numbers, you will see that X is not supported, and indeed there is no way to get hexadecimal output with to_char.
But you can use to_hex:
SELECT to_hex(7374961057827412212);
to_hex
══════════════════
66592002042458f4
(1 row)
The error message you see is because you entered the first argument in single quotes, so it is a string (data type text), but there is no to_char function to format strings as strings (they are already strings).

what does caret do in postgresql?

I'm playing hackthebox machine's and current one has a postgresql db in place. The query breaks with ' and appeas as follows:
ERROR: unterminated quoted string at or near "'" LINE 1: Select * from
cars where name ilike '%test'%' ^
I understand that % is being used to search within the query string for the characters provided but, What is ^ used for?
Bold highlights my test query
All my searches yielded resulst regarding regexes and caret signaling the start of the string. Plus other result about using cli or something like that.
Can anybody tell me what is it doing at the end of the query?
Your are looking for the use of the caret specifically within error messages.
If I run this query:
psql -c " Select * from cars where name ilike '%test'%'"
This is what I get, preserving line breaks and spaces:
ERROR: unterminated quoted string at or near "'"
LINE 1: Select * from cars where name ilike '%test'%'
^
The caret points to where on the previous line the error occurred. In this case, that is where the opening quote mark that never got closed was located.
If you are using a tool which malformats your error messages, you should consider changing to one that does not or otherwise figuring out how to fix it.

DB2: Need to extract string to the left of delimitere

I have a column that looks like this:
SBN:123456=1
SBN:1234=0
SBN:12345678=5
I need to extract everything left of the equal sign ('=') for every row. I attempted using SUBSTRING this way:
SELECT COLUMN1, SUBSTR(COLUMN2,1,LOCATE('=', COLUMN2)-1) AS STUFF FROM TABLE1;
Instead of extracting the text from the string, it gave me the error "The statement was not executed because a numeric argument of a scalar function is out of range." and I can't seem to figure out why. What am I doing wrong?
I'm using DB2 11.1.4.4 on AIX, just FYI.
I found the issue. There were some NULLs in the column that the query didn't like apparently. Got rid of those and it worked fine.

Postgresql invalid input syntax with windows CSV files

For some reason Postgresql wont read my CSV files in the form:
2017-10-20T21:20:00,124.502,CAM[CR][LF]
2017-10-20T21:21:00,124.765,CAM[CR][LF]
(thats an ISO compliant timestamp right?) into a table defined as:
CREATE TABLE ext_bsrn.spa_temp (
spadate TIMESTAMP WITHOUT TIME ZONE,
spa_azimuth NUMERIC,
station_id CHAR(3) )
WITH (oids = false);
It returns this error:
ERROR: invalid input syntax for type timestamp: "?2015-01-01T00:00:00"
CONTEXT: COPY spa_temp, line 1, column spadate: "?2015-01-01T00:00:00"
I don't understand why the '?' is shown inside the quotes in the error message, there's no characters before 2015 in my file (checked it in Notepad++ with noprint characters shown.)
I tried both windows (CRLF) and unix (LF) line ends, but neither makes any difference.
I also tried seperate date & time columns but then it just throws a similar error re the date field. "invalid input syntax for type date"
Does line 1 mean the first line or the second line (if there is a Line 0)?

Teradata INSTR in UNIX SHELL

INSTR and SUBSTRING are not working in SHELL SCRIPT
Hi
Iam Using INSTR and SUBSTRING in UNIX shell script. They are working in Teradata sql assistant but they both are not working in UNIX SHELL SCRIPT.
I changed SUBSTRING to SUBSTR and it worked. But i still have problem with INSTR. Can any one help me out.
Example :
select
case when SubRegion like '%REGION%' then SubRegion else SubRegion || ' '
|| 'REGION' end REGION_NAME,
SUBSTR(nodes FROM instr(nodes,'-',1,1)+1 for instr(nodes,'-',1,1)-1) AS node,
SgSpeed,
SgUtil,
PortCount,
CAST(WeekEndingDate as DATE) WEEKENDINGDATE
FROM RNL_VIEWS.WT_CmtsSgUtil
WHERE instr(nodes,'-') > 0
and WeekEndingDate = '2014-12-06'
ERROR:
SUBSTR(nodes FROM instr(nodes,'-',1,1)+1 for instr(nodes,'-',1,1)-1) AS n
ode,
$
*** Failure 3706 Syntax error: expected something between the word 'nodes'
and the 'FROM' keyword.
Statement# 1, Info =582
*** Total elapsed time was 1 second.
Thanks
Naveen
There are two variations of substring in Teradata:
SUBSTRING(str FROM startpos FOR length) -- Standard SQL
SUBSTR(str, startpos, length) -- Teradata SQL
SUBSTR(str FROM startpos FOR length) doesn't exist, but the ODBC driver might rewrite ODBC-style SUBSTRING(str, startpos, length). This is also done for other ODBC-functions like LEFT or MONTH. Whenever you try to submit such a query using CLI/.NET/JDBC it will fail.
To disable this rewrite you to need to check the 'Disable Parsing' in the ODBC driver's options.
Regarding INSTR, this is included since TD14 and should not cause any error.