Coalesce and To_Number in Hive - sql

i have the following teradata query and it can run on teradata. But when I run it on hive, the following error appears because to_number cannot run on hive.
Cast(Trim(Coalesce(To_Number(Substr(JT0004LOANTEXT,927,2)),'00')) AS INTEGER)AS
BI_LOAN_CHARACTER_CD
Error :
Error while compiling statement: FAILED: SemanticException [Error 10011]: Invalid function
To_Number
What should I change from the above query and what will the query look like?

Related

Keep getting error when trying to use '\copy' in sql

Here is the query I've been trying to run:
create or replace function save_to_csv(mesa text)
returns void as $$
begin
execute '\copy (select distinct aid::text,
rid::text,
did::text
from ' || mesa ||
')
to ''/home/datascientist/Data/User_Journey_Map/updated_data/all_ids/'|| mesa ||'_ids.csv''';
end;
$$
language 'plpgsql';
I keep getting this error:
SQL Error [42601]: ERROR: syntax error at or near "\"
Where: PL/pgSQL function save_to_csv(text) line 3 at EXECUTE
SQL statement "SELECT save_to_csv(mesa)"
PL/pgSQL function save_tables() line 21 at PERFORM
However, if I delete the ' \' before 'copy' I get this error:
SQL Error [58P01]: ERROR: could not open file "/home/datascientist/Data/User Journey Map/updated_data/all_ids/tca__clicked_ids.csv" for writing: No such file or directory
Hint: COPY TO instructs the PostgreSQL server process to write a file. You may want a client-side facility such as psql's \copy.
Where: SQL statement "copy (select distinct aid::text, rid::text, did::text from tca__clicked) to '/home/datascientist/Data/User Journey Map/updated_data/all_ids/tca__clicked_ids.csv'"
PL/pgSQL function save_to_csv(text) line 3 at EXECUTE
SQL statement "SELECT save_to_csv(mesa)"
PL/pgSQL function save_tables() line 21 at PERFORM
I've tried implementing the solutions given at:
PostgreSQL syntax error when using EXECUTE in Function
and
I am trying to copy a file, but getting error message , but neither have helped and I can't find anything else that looks helpful.

Concatenate string in ALTER statement in REDSHIFT (syntax error)

I want alter an external table in redshift. If execute this query:
alter table "name_table"
set location 'a string' ||
TO_CHAR((getdate()-1)::date, 'YYYYMMDD') || '/';
give me a syntax error:
SQL Error [500310] [42601]: Amazon Invalid operation: syntax error at or near "||"
Position: 135;
Maybe I must use dynamic SQL but I'm not sure how do that. Can someone help me?
EDIT:
I try to use a procedure for alter an external table, this doesn't give me a syntax error but return an error like this:
You can't alter an external table with function or procedure.
Do you want update?
update "name_table"
set location = 'a string' || TO_CHAR((getdate()-1)::date, 'YYYYMMDD') || '/';
I don't think location can be dynamic. Though you issue this statement in SQL, you can't use standard operators to build the S3 path. It's the same limitation as in good old COPY TO statement (target file can't be dynamic).

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. M

I am new to Hive. I have set up hive and I am using mysql to store the metadata for hive tables. I am able to launch hive. However when I try to create a simple table.
I get this error:
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:Exception thrown when executing query : SELECT DISTINCT 'org.apache.hadoop.hive.metastore.model.MTable' AS NUCLEUS_TYPE,
Here is what I tried,
hive> create external table employee (FirstName string,LastName string, EmployeeId string)
row format delimited
fields terminated by ',';
I have been doing some research but no luck..What could I be doing wrong?

Oracle UNISTR in SQL and PL/SQL

When I execute below query in SQL and in PL/SQL (stored procedure), both gives different results. Why is that?
Query: select UNISTR('\03A6') from dual;
Sql outputs Φ where as PL/SQL outputs F
I am using sql developer to execute both.
How can I make pl/sql return Φ
Function UNISTR expects a string as input parameter. Usually you should get error
ORA-00911: invalid character
when you run UNISTR(\03A6)
Try select UNISTR('\03A6') from dual; instead.

function cannot execute on segment because it issues a non-SELECT statement

I get the error "function cannot execute on segment because it issues a non-SELECT statement"
when I try to execute the following function. The function uses the value from generate_series and just returns 'yes' or 'no'
SELECT generate_series, vin_temp_test(generate_series) FROM options_t
options_t has the following data