Tera Data what the manifest json file for ? the purpose of it? - teradata

I have a sql command below, I don't understand what the flowdata_manifest.json for.
SELECT NodeId, AmpId, Sequence, ObjectName, ObjectSize, RecordCount
FROM WRITE_NOS_FM (
ON ( SELECT * FROM RiverFlowPerm )
PARTITION BY SiteNo ORDER BY SiteNo
USING
LOCATION('YOUR-STORAGE-ACCOUNT/RiverFlowPerm_PartitionBy/')
STOREDAS('PARQUET')
NAMING('DISCRETE')
MANIFESTFILE('YOUR-STORAGE-ACCOUNT/RiverFlowPerm_PartitionBy/flowdata_manifest.json')
INCLUDE_ORDERING('TRUE')
MAXOBJECTSIZE('4MB')
COMPRESSION('GZIP')
) AS d
ORDER BY AmpId;

Related

tera data how to use write_nos overwrite parquet file

I have a sql like this, executing it first time is ok and the second time will be fail. Because the file exist.
How to use write_nos overwrite parquet file ?
SELECT ObjectSize, RecordCount
FROM WRITE_NOS_FM (
ON ( SELECT * FROM RiverFlowPerm_csv )
USING
LOCATION('/s3/bigdaxxxxxx.s3.amazonaws.com/RiverFlowPerm/')
STOREDAS('PARQUET')
COMPRESSION('GZIP')
) AS d ;

Sqlite update with inner query select

According to all examples my query should be executing. I am trying to update new column on my table with the last 4 digits of the phone number like so :
UPDATE users
SET users.phone_last_4 = t.lastFour
FROM
(
select substr( phone_number, -4) as lastFour from users
) t;
Also tried this:
UPDATE users
SET users.phone_last_4 = t.lastFour
FROM
(
select substr( phone_number, -4) as lastFour from users
) AS t;
Both fail with same error :
near ".": syntax error: UPDATE users
SET users.
What could I possibly do wrong here?
SQLite does not support joins for the UPDATE statement and also this syntax containing FROM .
In your case I can't see why you need it.
Just do:
UPDATE users
SET phone_last_4 = substr(phone_number, -4)

Oracle sql : expression is of wrong type

I'm trying to write a PL/SQL to convert comma separated string into an array and iterate through that.
for that I created a datatype as follows:
"CODE_TABLE_TYPE" AS TABLE OF VARCHAR2(500)
crated a function - STR_TO_CODE_TABLE to convert the comma separated string in to the table of CODE_TABLE_TYPE.
and the PL/SQL looks like this:
FOR DEP IN ( SELECT * FROM TABLE ( CAST( STR_TO_CODE_TABLE( IN_DES_AIRPORTS ) AS CODE_TABLE_TYPE ) ) ) LOOP
SELECT * INTO RESULTS FROM MY_TABLE
WHERE IN_ID = MY_TABLE.ID
AND ( SELECT 1 FROM TEMP_TABLE WHERE DEPARTURE LIKE '%' || DEP || '%' )= 1;
END LOOP;
But it gives an error saying "expression is of wrong type". But the datatype is varchar2.
Can anyone please suggest what's the possible cause for this. What should I do to avoid this issue?

PL/SQL - comma separated list within IN CLAUSE

I am having trouble getting a block of pl/sql code to work. In the top of my procedure I get some data from my oracle apex application on what checkboxes are checked. Because the report that contains the checkboxes is generated dynamically I have to loop through the
APEX_APPLICATION.G_F01
list and generate a comma separated string which looks like this
v_list VARCHAR2(255) := (1,3,5,9,10);
I want to then query on that list later and place the v_list on an IN clause like so
SELECT * FROM users
WHERE user_id IN (v_list);
This of course throws an error. My question is what can I convert the v_list to in order to be able to insert it into a IN clause in a query within a pl/sql procedure?
If users is small and user_id doesn't contain commas, you could use:
SELECT * FROM users WHERE ',' || v_list || ',' LIKE '%,'||user_id||',%'
This query is not optimal though because it can't use indexes on user_id.
I advise you to use a pipelined function that returns a table of NUMBER that you can query directly. For example:
CREATE TYPE tab_number IS TABLE OF NUMBER;
/
CREATE OR REPLACE FUNCTION string_to_table_num(p VARCHAR2)
RETURN tab_number
PIPELINED IS
BEGIN
FOR cc IN (SELECT rtrim(regexp_substr(str, '[^,]*,', 1, level), ',') res
FROM (SELECT p || ',' str FROM dual)
CONNECT BY level <= length(str)
- length(replace(str, ',', ''))) LOOP
PIPE ROW(cc.res);
END LOOP;
END;
/
You would then be able to build queries such as:
SELECT *
FROM users
WHERE user_id IN (SELECT *
FROM TABLE(string_to_table_num('1,2,3,4,5'));
You can use XMLTABLE as follows
SELECT * FROM users
WHERE user_id IN (SELECT to_number(column_value) FROM XMLTABLE(v_list));
I have tried to find a solution for that too but never succeeded. You can build the query as a string and then run EXECUTE IMMEDIATE, see http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/dynamic.htm#i14500.
That said, it just occurred to me that the argument of an IN clause can be a sub-select:
SELECT * FROM users
WHERE user_id IN (SELECT something FROM somewhere)
so, is it possible to expose the checkbox values as a stored function? Then you might be able to do something like
SELECT * FROM users
WHERE user_id IN (SELECT my_package.checkbox_func FROM dual)
Personally, i like this approach:
with t as (select 'a,b,c,d,e' str from dual)
--
select val
from t, xmltable('/root/e/text()'
passing xmltype('<root><e>' || replace(t.str,',','</e><e>')|| '</e></root>')
columns val varchar2(10) path '/'
)
Which can be found among other examples in Thread: Split Comma Delimited String Oracle
If you feel like swamping in even more options, visit the OTN plsql forums.

dynamic table name in a query

How can I put a table name dynamically in a query?
Suppose I have a query as shown below:
Select a.amount
,b.sal
,a.name
,b.address
from alloc a
,part b
where a.id=b.id;
In the above query I want to use a table dynamically (part b if the database is internal, p_part b if the database if external).
I have a function that returns which database it is. Suppose the function is getdatabase();
select decode(getdatabase(),'internal','part b','external','p_part b')
from dual;
How can I use this function in my main query to insert the table name dynamically into the query?
I don't want to implement this using the primitive way of by appending strings to make a final query and then open cursor with that string.
I don't want to implement this with primitive way of by appending
strings to make a final query and then open cursor with that string .
That's really the only way you can do it. It's not possible to use a variable or function call for the table name when using a regular PL/SQL SQL block, you have to use dynamic SQL.
Refer to Oracle documentation for more details:
http://docs.oracle.com/cd/B10500_01/appdev.920/a96590/adg09dyn.htm
Here's an example from the doc:
EXECUTE IMMEDIATE 'SELECT d.id, e.name
FROM dept_new d, TABLE(d.emps) e -- not allowed in static SQL
-- in PL/SQL
WHERE e.id = 1'
INTO deptid, ename;
You can do this without dynamic SQL, assuming both tables (part and p_part) are available at compile time:
select a.amount
,b.sal
,a.name
,b.address
from alloc a
,part b
where a.id=b.id
and (select getdatabase() from dual) = 'internal'
UNION ALL
select a.amount
,b.sal
,a.name
,b.address
from alloc a
,p_part b
where a.id=b.id
and (select getdatabase() from dual) = 'external'
;
I've put the function call in a subquery so that it is run only once per call (i.e. twice, in this instance).

Resources