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`;
Intention: I want to subselect values within a coalesce function in MariaDB (10.7.1).
Problem:
Executing this SQL statement ...
select coalesce(select id from MY_TABLE limit 1);
... throws this error message:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'select id from MY_TABLE limit 1)' at line 1
Workarounds / checks I tried:
select id from MY_TABLE limit 1; returns a valid value. So that part of the statement is fine.
select coalesce('a'); returns the value a. So executing coalesce with one parameter only is also fine.
You must make the result of select to be an expression. Statement is not an expression
with MY_TABLE as (
select 1 as id
)
select coalesce((select id from MY_TABLE limit 1)) c;
Note the result of LIMIT without ORDER BY is an arbitrary row.
The COALESCE function typically takes 2 or more arguments. The value returned is the first value which is not NULL. You probably intend something like this:
SELECT COALESCE(id, 'missing') AS id
FROM MY_TABLE
ORDER BY <some column>
LIMIT 1;
Below (1) is the query which I wrote and when I am not using CAST i am getting error (2) and when am using cast its throwing another syntax error(3)
(1)
/*DROP TABLE IF EXISTS LFB1_BACKUPTABLE
CREATE TABLE LFB1_BACKUPTABLE AS
(SELECT * FROM LFB1);
*/
INSERT INTO LFB1_BACKUPTABLE (
MANDT,LIFNR,BUKRS,PERNR,ERDAT,ERNAM,SPERR,LOEVM,ZUAWA,
AKONT,BEGRU,VZSKZ,ZWELS,XVERR,ZAHLS,ZTERM,EIKTO,ZSABE,
KVERM,FDGRV,BUSAB,LNRZE,LNRZB,ZINDT,ZINRT,DATLZ,XDEZV,
WEBTR,KULTG,REPRF,TOGRU,HBKID,XPORE,QSZNR,QSZDT,QSSKZ,
BLNKZ,MINDK,ALTKN,ZGRUP,MGRUP,UZAWE,QSREC,QSBGR,QLAND,
XEDIP,FRGRP,TOGRR,TLFXS,INTAD,XLFZB,GUZTE,GRICD,GRIDT,
XAUSZ,CERDT,CONFS,UPDAT,UPTIM,NODEL,TLFNS,AVSND,AD_HASH,
J_SC_SUBCONTYPE,J_SC_COMPDATE,J_SC_OFFSM,J_SC_OFFSR,
BASIS_PNT,GMVKZK,PREPAY_RELEVANT,ASSIGN_TEST, CAST(_CELONIS_CHANGE_DATE AS DATE) AS _CELONIS_CHANGE_DATE
)
SELECT DISTINCT * FROM LFB1
WHERE MANDT||LIFNR||BUKRS NOT IN (SELECT DISTINCT MANDT||LIFNR||BUKRS FROM
LFB1_BACKUPTABLE);
(2) Execution error:
[Vertica]VJDBC ERROR: Column "_CELONIS_CHANGE_DATE" is of type timestamptz but expression is of type varchar
(3) Execution error:
[Vertica]VJDBC ERROR: Syntax error at or near "CAST"
Why are you using a cast statement in your insert table column list? You can't change the type of the destination table columns.
You need to change the type of the values you are inserting.
INSERT INTO LFB1_BACKUPTABLE (
MANDT,LIFNR,BUKRS,PERNR,ERDAT,ERNAM,SPERR,LOEVM,ZUAWA,
AKONT,BEGRU,VZSKZ,ZWELS,XVERR,ZAHLS,ZTERM,EIKTO,ZSABE,
KVERM,FDGRV,BUSAB,LNRZE,LNRZB,ZINDT,ZINRT,DATLZ,XDEZV,
WEBTR,KULTG,REPRF,TOGRU,HBKID,XPORE,QSZNR,QSZDT,QSSKZ,
BLNKZ,MINDK,ALTKN,ZGRUP,MGRUP,UZAWE,QSREC,QSBGR,QLAND,
XEDIP,FRGRP,TOGRR,TLFXS,INTAD,XLFZB,GUZTE,GRICD,GRIDT,
XAUSZ,CERDT,CONFS,UPDAT,UPTIM,NODEL,TLFNS,AVSND,AD_HASH,
J_SC_SUBCONTYPE,J_SC_COMPDATE,J_SC_OFFSM,J_SC_OFFSR,
BASIS_PNT,GMVKZK,PREPAY_RELEVANT,ASSIGN_TEST, _CELONIS_CHANGE_DATE
)
SELECT DISTINCT col1, col2, col3, ..., timestamp_col::DATE FROM LFB1
WHERE MANDT||LIFNR||BUKRS NOT IN (SELECT DISTINCT MANDT||LIFNR||BUKRS FROM LFB1_BACKUPTABLE);
Your syntax for casting to a date is syntactically correct, but in this example I used the more common Vertica syntax which is col::DATE, both will work.
I have a database where there is a column of varchar that I wish to convert to a timestamp. I'd like to do something like this, but keep getting a syntax error, please can someone advise?
ALTER TABLE MY_TABLE
ALTER COLUMN MY_COLUMN TYPE timestamp
USING to_timestamp(MY_COLUMN::double precision);
MY_COLUMN is of type VARCHAR(255) NOT NULL
Error reads:
Syntax error in SQL statement "ALTER TABLE MY_TABLE
ALTER COLUMN MY_COLUMN TYPE TIMESTAMP
USING[*] TO_TIMESTAMP(MY_COLUMN::DOUBLE PRECISION) "; SQL statement:
ALTER TABLE MY_TABLE
ALTER COLUMN MY_COLUMN TYPE timestamp
USING to_timestamp(MY_COLUMN::double precision) [42000-176] 42000/42000
It would appear that my Postgresql running within Grails doesn't support to_timestamp. As pointed out by #a_horse_with_no_name in the comments of the question, the code works. Thanks for pointing out sqlfiddle.com, I hadn't realised such a resource existed.
I have a Table Function it return a table of (student_id,student_name)
I want to call it and insert the result into another table
I use
INSERT INTO STUDENT_TMP SELECT Table(MyDB.fn_getStudent())
but i did not get the result
I have got an error :
ERROR: DB2 SQL Error: SQLCODE=-390, SQLSTATE=42887,
SQLERRMC=MyDB.AA;SQL131208155041300,DRIVER=3.67.26
Error Code: -390
I found the followin exsample on ibm sites:
select t1.timeid, t1.storeid, t1.sales
from time, store, table (cvsample.salesfunc(time.timeid, store.storeid)) as t1
where time.timeid = t1.timeid and store.storeid = t1.storeid;
notice the syntax: table (cvsample.salesfunc(time.timeid, store.storeid)) as t1
so you prob dont need fields and 'as' you still need '*' and the 'FROM'
so
INSERT INTO STUDENT_TMP SELECT * FROM Table (MyDB.fn_getStudent())