teradata

Drop rows identified within moving time window

和自甴很熟 提交于 2020-01-16 00:36:14
问题 I have a dataset of hospitalisations ('spells') - 1 row per spell. I want to drop any spells recorded within a week after another (there could be multiple) - the rationale being is that they're likely symptomatic of the same underlying cause. Here is some play data: create table hif_user.rzb_recurse_src ( patid integer not null, eventdate integer not null, type smallint not null ); insert into hif_user.rzb_recurse_src values (1,1,1); insert into hif_user.rzb_recurse_src values (1,3,2); insert

SQL prototype design: facing silent truncation of data using varchar(N) — any better alternatives? (Teradata)

蓝咒 提交于 2020-01-15 04:01:46
问题 Situation: varchar(20) seems to truncate silently in Teradata and not to expand or complain when encountering strings larger than 20 characters long... This is a bit of a surprise as I expected either automatic expansion of the column to fit larger strings, say 30 characters, OR for an error to be thrown if a larger string were encountered. Silent truncation seems to get me the worst of all worlds... Complication: For my application (prototype analytics design) I don't know in advance how

Teradata : How to get the server name using query

不羁的心 提交于 2020-01-14 13:33:48
问题 How can I get the server name using query in Teradata? That is, if I am writing a query on the 'dev' server, it should return the dev server name. for example, in Sybase : we will be using select @@servername. 回答1: There's nothing like @@servername in TD. You might create a SQL UDF on each server returning the name, e.g. REPLACE FUNCTION syslib.#servername () RETURNS VARCHAR(30) LANGUAGE SQL CONTAINS SQL DETERMINISTIC RETURNS NULL ON NULL INPUT SQL SECURITY DEFINER COLLATION INVOKER INLINE

how to join tables by comparing two fields, and also considering performance

允我心安 提交于 2020-01-14 02:29:23
问题 This should be simple but I can't get it. I need to do a select to get newer date values for some accounts. I start here, T1: +----------+---------+ | date | account | +----------+---------+ | 4/1/2018 | 1 | | 4/1/2018 | 2 | | 4/1/2018 | 3 | | 4/1/2018 | 4 | | 4/1/2018 | 5 | +----------+---------+ Then some dates are updated in T2: +----------+---------+ | date | account | +----------+---------+ | 7/1/2018 | 1 | | 7/1/2018 | 2 | +----------+---------+ How can I get this output into T3,

Teradata variable with list of values

本小妞迷上赌 提交于 2020-01-11 12:54:32
问题 Is there a way to pass a list of values in a variable and use that in an IN() statement to check a field against the passed in list of values? The only thing I can think of is something like this: SELECT field_name WHERE (SELECT INSTR(@variable_list, field_name))>0 Thanks. 回答1: TD14 supports a nice table function called STRTOK_SPLIT_TO_TABLE: REPLACE MACRO testmac(param VARCHAR(1000)) AS ( SELECT * FROM dbc.DatabasesV AS db JOIN ( SELECT token AS DatabaseName, tokennum FROM TABLE (STRTOK

check if volatile table exists in teradata

风格不统一 提交于 2020-01-11 06:01:06
问题 Volatile table are great and somewhat comparable to temp tables in sql server (my background). Is there a way to check if a volatile table exists already? This code won't work when it is run for the first time: DROP TABLE SomeVolatileTable; CREATE VOLATILE TABLE SomeVolatileTable AS ( SELECT TOP 10 * FROM SomeSourceTable ) WITH DATA ON COMMIT PRESERVE ROWS; In sql server you can check if a temporary table exists: IF OBJECT_ID('tempdb..#SomeTempTable') IS NOT NULL DROP TABLE #SomeTempTable

ValueError: character U+590048 is not in range [U+0000; U+10ffff] - MAC OS

大兔子大兔子 提交于 2020-01-06 06:31:21
问题 Could someone help me with the below error while connecting to Teradata from my Python environment. I'm using ODBC driver method and I've tried all the below existing methods to connect but no luck. Note: if you are using windows, you can directly use these methods, however the problem comes when you are on MAC OS (not for all though) USING TERADATA Module and SQL Alchemy. import teradata import pyodbc server='111.00.00.00' username = 'user' password = 'pwd' udaExec = teradata.UdaExec(appName

rows between 1 preceding and preceding 1

空扰寡人 提交于 2020-01-06 06:06:09
问题 I am new to SQL and I want to know what exactly the function ( rows between 1 preceding and 1 preceding )do in teradata ,I want a simple clarification please ,I am trying to use this function as a testcase to get the time gaps in history table between start and end date,can anyone help please or provide any useful links. SELECT DISTINCT CUST_ID FROM ( SELECT CUST_ID, STRT_dt - MIN(END_dt) OVER (PARTITION BY CUST_ID ORDER BY END_dt ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) AS diff FROM table

Reversing a string using Teradata SPL

丶灬走出姿态 提交于 2020-01-06 01:52:07
问题 How can I reverse a string using Teradata Stored Procedure Language (SPL) ? The requirement was to replicate the SQL-Server replace() function. This could be achieved by writing a corresponding UDF in Teradata but I want to achieve the same using a Procedure. The procedure could be then used to initialize the variable before its use in the actual statement having reverse(). 回答1: This can be achieved using he following Stored Procedure. The main logic behind it is that in each iteration

Teradata-jdbc: What's the point of using Fastload if java has memory limitations?

若如初见. 提交于 2020-01-05 19:36:53
问题 Here is the link to a sample jdbc Fastload program from the teradata website : http://developer.teradata.com/doc/connectivity/jdbc/reference/current/samp/T20205JD.java.txt It inserts only one row so I modified it to insert 500K rows by replacing the following code : pstmt.setInt(1, 1); pstmt.setString(2, strBuf); pstmt.addBatch(); batchCount++; with : for (int i = 0; i < 500000 ; i ++ ) { pstmt.setInt(1, i); pstmt.setString(2, strBuf); pstmt.addBatch(); batchCount++; } It of course failed