create or replace
mythirdproject-345809.Test_dataset.Head_Of_country_cdc as select * ,
current_timestamp as created_dt, current_timestamp as last_updated_dt,
'Initial Load' as last_updated_by, from
mythirdproject-345809.Test_dataset.Head_Of_country;
I tried creating a table using sql query in bigquery but i am getting error
(mythirdproject is not a supported object type at [1:19])
This happens because you don't specify the type of object that you are trying to create. The correct command is CREATE [OR REPLACE] TABLE <table_name> so your query should be:
CREATE OR REPLACE TABLE `mythirdproject-345809.Test_dataset.Head_Of_country_cdc` AS
SELECT * ,
CURRENT_TIMESTAMP AS created_dt,
CURRENT_TIMESTAMP AS last_updated_dt,
'Initial Load' AS last_updated_by
FROM `mythirdproject-345809.Test_dataset.Head_Of_country`;
Related
My table is :
CREATE STABLE basedb.actionlog (addtime TIMESTAMP, action_ip binary(32), modelname binary(32), acttype binary(8), remark nchar(255)) TAGS (user_id INT,username nchar(16));
The query statement is :
SELECT acttype,count(acttype) as countact FROM actionlog WHERE addtime>'2018-10-03 14:38:05.000' INTERVAL(1d) group by acttype
Then there is an error:
invalid SQL: column projection is not compatible with interval
(0.000235s)
I cann't tell what the reason is.
I have a table which is partitioned by day .I tried inserting the data by setting
set hivevar:ds=2018-12-01;
then using ** INSERT OVERWRITE table XTABLE partition(day='${hivevar:ds}') **
which is working fine
but when i do like below
set hivevar:pd=date_add('${hivevar:ds}',-1);
then ** INSERT OVERWRITE table XTABLE partition(day='${hivevar:pd}') **
it is throwing error. i think problem is because of extra quotes but not able to find how to solve.
error is :
cannot recognize input near ''date_add('' '2018' '-' in constant
MYCODE:
set hivevar:ds=2018-12-01;
set hivevar:pd=date_add('${hivevar:ds}',-1);
set hive.exec.dynamic.partition.mode=nonstrict;
CREATE TABLE IF NOT EXISTS XTABLE (emp_id BIGINT, start_time STRING, end_time STRING)
PARTITIONED BY(day STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
--THIS IS WORKING FINE
INSERT OVERWRITE table XTABLE partition(day='${hivevar:ds}')
select distinct d.emp_id, d.start_time, d.end_time from
(
select emp_id, start_time, end_time from XTABLE where day='${hivevar:ds}'
) d;
--THIS IS THROWING AN ERROR cannot recognize input near ''date_add('' '2018' '-' in constant
--SEEMS PROBLEM IS WHILE SETTING THE VARIABLE
INSERT OVERWRITE table XTABLE partition(day='${hivevar:pd}')
select distinct d.emp_id, d.start_time, d.end_time from
(
select emp_id, start_time, end_time from XTABLE where day='${hivevar:pd}'
) d;
if success it should give message like below:
Loading data to table xtable partition (day=2018-12-01)
Currently you are trying to insert using static partition with function in it's specification. You can use dynamic partition insert, providing partition in the dataset:
set hivevar:ds=2018-12-01;
set hive.exec.dynamic.partition.mode=nonstrict;
INSERT OVERWRITE table XTABLE partition(day)
select distinct d.emp_id, d.start_time, d.end_time from
(
select emp_id, start_time, end_time, day --partition present in dataset, also it can be date_sub('${hivevar:ds}',1) as day
from XTABLE where day=date_sub('${hivevar:ds}',1);
) d;
This will work, but it may cause table full scan because partition pruning does not work with functions. So, the best solution is to calculate date-1 day in the shell and pass it as a parameter inside HQL script:
ds=$(date +"%Y-%m-%d" --date " -1 day")
hive --hiveconf ds="$ds" -f your_script.hql
And inside your script use '${hiveconf:ds}'
#saicharan You cannot add a function while setting a variable.
I had faced a similar issue.
set hivevar:ds='should always have a static value'
To solve this issue, you need to create a simple script as below:
ds=`date -d "+1 day" +"%Y-%m-%d"`
echo $ds
hive --hivevar ds="${ds}" -e "INSERT OVERWRITE table XTABLE partition(day='${hivevar:ds}') "
This should solve your problem. Let me know if it works.
I have MariaDB and Oracle databases. I have set up ODBC Connect between the two, so that I can access Oracle from MariaDB.
I can do the following from MariaDB:
CREATE TABLE oracopy ENGINE=connect TABLE_TYPE=ODBC tabname='testtab' CONNECTION='DSN=ORCL';
This creates a table locally.
What I really want to do however is run a Query on the remote Oracle and return the results to the MariaDB session.
The query would be Oracle speficic, i.e. might containing ORACLE functions like DECODE. Also the query could include a PLSQL function call which again would need to be run on Oracle. E.g:
SELECT t.id, DECODE( t.typ,'HH', 'Val 1', 'Val 2' ) tt,
my_package.fn_test ( t.dob ) dob
FROM testtab t;
Does MariaDB have a "run this query on XXX remote database".
Consider using the source definition argument, SRCDEF, as shown in docs.
CREATE TABLE oracopy ENGINE=connect TABLE_TYPE=ODBC CONNECTION="DSN=ORCL"
SRCDEF="SELECT t.id, DECODE( t.typ,'HH', 'Val 1', 'Val 2' ) tt,
my_package.fn_test ( t.dob ) dob
FROM testtab t;"
CREATE TABLE #TempAnnualOnline
(
TrainingStatus nvarchar(70),
FirmEmployeeID nvarchar(25),
DepartmentID nvarchar(25),
StartDate datetime,
SectionDate datetime,
TrainingSessionID uniqueidentifier
)
INSERT INTO #TempAnnualOnline
select 'Users Not Started' , '1535' , '0100' , '2017-04-17 00:00:00' , NULL , NEWID()
I have researched this issue so I don't believe it is a duplicate but please mark it if it is.
On the last item of the select statement, instead of specifying a GUID I have the NEWID() function.
When I run it the way it is, I get this error.
Column name or number of supplied values does not match table
definition.
When I take the TrainingSessionID out of the Table and the NEWID() it works fine.
I am nearly certain I am supplying the right amount of columns to the select.
Is there something about using NEWID() with INSERT INTO SELECT that I am not getting?
Your code is fine. You have something wrong somewhere else causing this error.
Try to explicitly define your insert columns and see if the issue persists.
INSERT INTO #TempAnnualOnline
(TrainingStatus,
FirmEmployeeID,
DepartmentID,
StartDate,
SectionDate,
TrainingSessionID)
select 'Users Not Started' , '1535' , '0100' , '2017-04-17 00:00:00' , NULL , NEWID()
Or
INSERT INTO #TempAnnualOnline
(TrainingStatus,
FirmEmployeeID,
DepartmentID,
StartDate,
SectionDate,
TrainingSessionID)
Values ('Users Not Started' , '1535' , '0100' , '2017-04-17 00:00:00' , NULL , NEWID())
I am not certain why yours doesn't work because it does for me. However if you want to tweak your insert slightly, you can use a SELECT INTO. Added bonus, you don't need to define the temp table columns.
SELECT
'Users Not Started' AS [TrainingStatus]
,'1535' AS FirmEmployeeID
,'0100' AS [DepartmentID]
,'2017-04-17 00:00:00' AS [StartDate]
,NULL AS [SectionDate]
,NEWID() AS [TrainingSessionID]
INTO #TempAnnualOnline
SELECT * FROM [#TempAnnualOnline]
DROP TABLE #TempAnnualOnline
Refreshing SQL Server Management Studio seemed to fix this issue. After closing and reopening the entire thing I ran this exact script with no changes and it worked.
Odd.
I had executed this script a number of times prior to making this modification, dropping and recreating this table each time.
It seemed that there just needed to be a clean slate created.
Thanks to all who verified the script was correct syntax wise.
Also in the future, I will be adapting #AlexanderHiggins, explicitly defining columns upfront just to avoid confusion.
I have a Informix database. This database contain a stored procedure with name of 'sp_agent_details' that get two DateTime Parameter. This stored procedure results about 27 columns and I want only few columns of it for reporting. I try this syntax:
select AGENT_NAME, AGENT_LOGIN_ID from
TABLE(sp_agent_detail('2014-02-04 04:00:00', '2014-02-04 23:00:00'))
This Result such Error:
java.sql.SQLException: Illegal SQL statement in SPL routine.
Next I try this syntax:
select AGENT_NAME, AGENT_LOGIN_ID from
TABLE(MULTISET{sp_agent_call_summary
('2014-02-04 04:00:00', '2014-02-04 23:00:00')})
Result:
java.sql.SQLException: Function (informix.sp_agent_call_summary)
returns too many values.
You have to map your result columns of the SP to columnames (in the order they are returned by the procedure ! ).
So your statement will become:
select AGENT_NAME, AGENT_LOGIN_ID from
TABLE(sp_agent_detail('2014-02-04 04:00:00', '2014-02-04 23:00:00'))(AGENT_NAME, AGENT_LOGIN_ID, other columns that are returned by your SP)