User carlos a. ibarra - TeradataQuestions most recent 30 from http://teradataquestions.com 2010-09-09T16:08:43Z http://teradataquestions.com/feeds/user/2 http://www.creativecommons.org/licenses/by-nc/2.5/rdf http://teradataquestions.com/questions/73/teradata-sql-assistant-takes-forever-to-interrupt-large-answerset/140#140 Answer by Carlos A. Ibarra for Teradata SQL Assistant takes forever to interrupt large answerset Carlos A. Ibarra 2010-05-10T21:57:55Z 2010-05-10T21:57:55Z <p>This only happens if I submit the query with F9 (run in parallel) instead of F5. According to Teradata, they can't tell if more resultsets are coming, so they can't abort the query and have no choice but to ignore the remaining rows. To get the desired behavior, use F5.</p> http://teradataquestions.com/questions/73/teradata-sql-assistant-takes-forever-to-interrupt-large-answerset Teradata SQL Assistant takes forever to interrupt large answerset Carlos A. Ibarra 2010-02-11T03:30:41Z 2010-05-10T21:57:55Z <p>I am using Teradata SQL Assistant version 13.0.0.08 on Windows. I think it's the version written in C#.</p> <p>When I run a query that returns more than 2000 rows, which is my max in the options for rows to display, and it asks me if I want to cancel after 2000 rows and I click Yes, I expect it to immediately give me back control. Instead, it still takes a long time (sometimes minutes) to come back. During this time, SQL Assistant is unresponsive and the query pane background is light red, like it's busy. I have checked the network activity and it appears that the rest of the rows are still being read from Teradata. Very annoying.</p> <p>This happens the same way whether I am using the .Net provider or ODBC to connect to Teradata. I have looked through all the options but nothing seems like it would help. Tomorrow I will try installing a slightly newer version that I think is available.</p> <p>How can I fix this?</p> http://teradataquestions.com/questions/104/difference-between-delete-and-delete-all/105#105 Answer by Carlos A. Ibarra for Difference between 'Delete' and 'Delete All' Carlos A. Ibarra 2010-03-30T23:16:55Z 2010-04-01T01:07:10Z <p>There is no difference. At one point the manuals seemed to imply that DELETE ALL was different from DELETE but that was later understood to be a misinterpretation.</p> <p>See Dieter Noeth's answer to this <a href="http://forums.teradata.com/forum/database/delete-all-vs-delete" rel="nofollow">question</a></p> http://teradataquestions.com/questions/93/teradata-metadata-help/97#97 Answer by Carlos A. Ibarra for Teradata metadata help Carlos A. Ibarra 2010-03-17T19:22:42Z 2010-03-17T19:22:42Z <p>If DBQL is set up to log with enough detail in your system, you can use the DBC.QryLogObjects view to determine what database columns are accessed by your query. The tricky part if finding your query in the log. The following technique uses "label queries" around your query to bracket what you want to examine in the log. Make sure you wait 10 minutes or whatever your DBQL flush interval is before running the summary query.</p> <pre><code>-- These selects should bracket your query select 'BeginQueryTracking001'; -- your query here: Select a.columnA,b.ColumnB from subjectarea1.table1 a left outer join subjectarea2.table2 b on a.id = b.id; select 'EndQueryTracking001'; -- Wait 10 minutes before issuing this summary query that returns your object names. -- Make sure that the BeginQueryTracking001/EndQueryTracking001 match what you used above. select distinct O.objectdatabasename,O.objecttablename,O.objectcolumnname from dbc.qrylog L1 join dbc.qrylog L2 on L1.sessionid=l2.sessionid and L1.starttime &lt; L2.starttime and L1.querytext = 'select ''BeginQueryTracking001'';' and L2.querytext = 'select ''EndQueryTracking001'';' join dbc.qrylog M on M.sessionid = L1.sessionid and L1.starttime &lt; M.starttime and M.starttime &lt; L2.starttime join dbc.qrylogobjects O on M.queryid = o.queryid and O.objectcolumnname is not null order by 1,2,3 </code></pre> http://teradataquestions.com/questions/91/speeding-up-select-maxtimestamp-column-from-t-when-t-is-loaded-via-continuous Speeding up SELECT MAX(timestamp_column) FROM T, when T is loaded via continuous TPump Carlos A. Ibarra 2010-03-13T15:57:19Z 2010-03-14T16:22:07Z <p>How can I speed up a query that's currently doing a full table scan to get the maximum value of a timestamp column?</p> <p>I have a large table with a timestamp column. There is a TPump running all day with many sessions inserting and updating rows, serialized using the PI. I need to run the equivalent of:</p> <pre><code>SELECT MAX(ts) FROM TABLE1 </code></pre> <p>many times a day, which does a full table scan. Is there any index that can be added or something that can be done to speed this up?</p> <ul> <li>A normal NUSI will not be used by Teradata because it is not ordered.</li> <li>A value-ordered NUSI cannot be created on a timestamp column.</li> <li>I cannot use an aggregate join index that precomputes the max because the AGI will have a different PI from the table, causing the different TPump sessions to block each other when updating the singe AGI value.</li> <li>I cannot reduce the number of TPump sessions to 1 to avoid the AGI blocking problem because the feed requires a high update rate.</li> </ul> <p>The best solution I have up to now is to change the tpump to keep another table updated that keeps the max(ts) for large enough groups of rows, so that the number of groups is small enough to make the SELECT max(ts) run fast, but large enough to get enough parallelism in the TPump to not become a bottleneck for the TPump. The TPump would have to use a different serialization key appropriate for this table's PI.</p> <p>I would prefer is something could be done inside Teradata without having to create more tables or change the Tpump.</p> http://teradataquestions.com/questions/81/how-to-interpret-value-of-field-createdate-in-tdwm-tables/82#82 Answer by Carlos A. Ibarra for How to interpret value of field 'CreateDate' in TDWM tables? Carlos A. Ibarra 2010-03-02T03:21:51Z 2010-03-02T03:21:51Z <p>Teradata dates are stored as integers encoded as:</p> <pre><code> (year-1900) * 10000 + month * 100 + day </code></pre> <p>This makes them look pretty reasonable for dates before the year 2000, for example</p> <ul> <li>690720 represents 1960-07-20</li> <li>840523 represents 1984-05-23</li> <li>991231 represents 1999-12-31</li> </ul> <p>For dates after 2000, (year-1900) is at least 100, so the date integer is more than 1 million, thus that pesky 1 at the beginning:</p> <ul> <li>1010911 represents 2001-09-11</li> <li>1091114 represents 2009-11-14</li> <li>1100301 represents 2010-03-01</li> </ul> http://teradataquestions.com/questions/79/does-rollbackprioritytrue-mean-to-use-rush-or-no-rush-for-rollbacks Does RollbackPriority=TRUE mean to use Rush or No Rush for rollbacks? Carlos A. Ibarra 2010-02-26T16:21:58Z 2010-02-27T17:46:36Z <p>This DBSControl setting is supposed to control whether rollbacks run at Rush priority or not. They used to always run at Rush because Teradata wanted to get them out of the way as soon as possible, but later they provided this RollbackPriority DBSControl parameter so the DBA can decide. However, it is not clear whether setting it to TRUE means that the rollback runs at Rush or not. </p> <p>Does TRUE mean that rollbacks run at Rush or that they run at the user's logon priority?</p> <p>The help for this setting is comically ambiguous:</p> <ol> <li>RollbackPriority - This Field defines the system default for the rollback priority. This allows the DBA to either take the default priority of Rush or the user's logon priority. To enable this feature set the field to TRUE. To disable the feature set the field to FALSE. Note that this new feature will affect all users on the system.</li> </ol> http://teradataquestions.com/questions/61/how-to-perform-bit-wise-operations-in-sql/62#62 Answer by Carlos A. Ibarra for How to perform Bit-wise operations in SQL? Carlos A. Ibarra 2010-01-19T01:52:51Z 2010-02-16T12:31:33Z <p>Teradata doesn't have bitwise operations out of the box.</p> <p>However if you can install a UDF pack, check out the <a href="http://www.teradata.com/DownloadCenter/Topic9226-139-1.aspx" rel="nofollow">Teradata UDFs for Byte Operations</a> package.</p> <p>Also, it is possible to do bit operations with the help of a table of powers of 2. Something like this:</p> <pre><code> create table bitmask(i integer, mask integer); insert into bitmask(0,1); insert into bitmask(1,2); insert into bitmask(2,4); insert into bitmask(3,8); insert into bitmask(4,16); insert into bitmask(5,32); -- 1 | 2 select coalesce(sum(a.mask),0) answer from bitmask a where (1/a.mask) mod 2 = 1 or (2/a.mask) mod 2 = 1; Answer: 3 -- 5 &amp; 9 select coalesce(sum(a.mask),0) answer from bitmask a where (5/a.mask) mod 2 = 1 and (9/a.mask) mod 2 = 1; Answer: 1 -- 5 XOR 9 select coalesce(sum(a.mask),0) answer from bitmask a where (5/a.mask) mod 2 &lt;&gt; (9/a.mask) mod 2; Answer: 12 </code></pre> http://teradataquestions.com/questions/51/order-by-issues/55#55 Answer by Carlos A. Ibarra for order by issues Carlos A. Ibarra 2010-01-07T22:50:48Z 2010-01-07T22:50:48Z <p>You can't use <em>count</em> as a column name because it's a reserved word. I changed it to <em>c</em> and simplified your query a bit.</p> <p>Here is how you can get your desired ordering:</p> <pre><code>SELECT case when grouping(pname) = 1 then 'Total' when grouping(version) = 1 then 'Subtotal ' || pname else pname end "NAME", version "VERSION", SUM(c) "Qty" FROM ( SELECT pname, version, 1 c from tt )as derived_table GROUP BY rollup (pname,version) order by grouping(pname),pname,grouping(version); </code></pre> http://teradataquestions.com/questions/53/rounding-increase-by-1/54#54 Answer by Carlos A. Ibarra for Rounding increase by 1 Carlos A. Ibarra 2010-01-07T22:29:57Z 2010-01-07T22:29:57Z <p>Rounding is the default behavior when casting to a lower precision decimal. For example:</p> <pre><code>select cast(72.7 as decimal(2)) Answer: 73 </code></pre> http://teradataquestions.com/questions/27/least-function-in-td/28#28 Answer by Carlos A. Ibarra for Least function in TD Carlos A. Ibarra 2009-11-10T14:01:23Z 2009-11-10T14:01:23Z <p>Teradata doesn't have a built-in least function.</p> <p>You could have your DBA install the <a href="http://www.teradata.com/DownloadCenter/Topic9228-137-1.aspx" rel="nofollow">Teradata UDFs for popular Oracle functions</a> pack that contains a least() function, although that UDF only handles two arguments. If you are going to keep doing a lot of Oracle-like stuff, it might be a good idea to install this pack anyway.</p> <p>To apply the two-argument UDF least to more arguments, you can do: </p> <pre><code> least(least(a,b),c) least(least(least(a,b),c),d) </code></pre> <p>You could also use a CASE statement like this:</p> <pre><code>-- for two values case when a &lt; b then a else b end -- for three values case when a &lt; b then case when a &lt; c then a else c end else -- b &lt; a case when b &lt; c then b else c end end </code></pre> <p>And so on, but the number of lines of code you have to write becomes big really fast if more values need to be compared.</p> http://teradataquestions.com/questions/25/2665-invalid-date/26#26 Answer by Carlos A. Ibarra for 2665 Invalid Date Carlos A. Ibarra 2009-11-05T12:25:44Z 2009-11-05T12:25:44Z <p>The format DD-MMM-YYYY doesn't match the date string 1-01-2008. Your could change the Java program to produce a two-digit day or preprocess the file to fix it.</p> <p>Depending on which utility you are using to load the file, you may be able to use a CASE statement like this:</p> <pre><code>insert into Tablea ... case when character_length(:datestring) &lt; 10 then '0'||:datestring else :datestring end </code></pre> http://teradataquestions.com/questions/18/6760-invalid-timestamp/20#20 Answer by Carlos A. Ibarra for 6760 Invalid timestamp Carlos A. Ibarra 2009-10-27T12:19:05Z 2009-10-29T20:04:07Z <p>You didn't post your CREATE TABLE statement but I think you defined end_date as a timestamp type column. If so, you don't need to cast current_timestamp(0) to CHAR. Just use:</p> <pre><code> update tablea set status = 'Succeeded' , end_date = current_timestamp(0) where id = 3456; </code></pre> <p>The data in timestamp columns is not kept in any specific format. The format in the column definition is used as the default output format when converting the timestamp to char for output. If you want to output in that format, you can define the column like this:</p> <pre><code>create table tablea ( id integer not null, status char(20), end_date timestamp(0) format 'dd/mm/y4bhh:mi:ss' ) primary index(id); insert into tablea values (3456, 'ok',current_timestamp(0)); update tablea set status = 'Succeeded' , end_date = current_timestamp(0) where id = 3456; help table tablea; </code></pre> <p>Now when you convert the column to char you get the format you want:</p> <pre><code>select cast(end_date as char(19)) from tablea; end_date 29/10/2009 14:59:31 </code></pre> http://teradataquestions.com/questions/16/the-format-or-data-contains-a-bad-character/17#17 Answer by Carlos A. Ibarra for The format or data contains a bad character Carlos A. Ibarra 2009-10-25T16:34:52Z 2009-10-25T16:34:52Z <p>The best way would be to have your DBA install the Is_numeric() User Defined Function (UDF) from the Teradata Download Center <a href="http://www.teradata.com/DownloadCenter/Topic9236-129-1.aspx" rel="nofollow">here</a>. Then you can do something like this, which converts the valid ones and returns invalid ones as -1.</p> <pre><code>select case when is_numeric(customer_no)=0 then cast(customer_no as decimal(18)) else -1 end from CUSTOMER_TABLE ; </code></pre> <p>You can check which UDFs are installed by running this query. If a UDF is installed, it will appear as a row in the result.</p> <pre><code>select * from dbc.udfinfo; </code></pre> <p>If you don't have the is_numeric, but you have the ostranslate UDF installed, you can do this:</p> <pre><code>select case when otranslate(customer_no,'0123456789','')='' then cast(customer_no as decimal(18)) else -1 end from CUSTOMER_TABLE ; </code></pre> <p>Finally, if you can't use these UDFs, you can test whether your varchar is composed of all digits like this:</p> <pre><code> select case when index('0123456789',substr(customer_no,1,1))&gt;0 and index('0123456789',substr(customer_no,2,1))&gt;0 and index('0123456789',substr(customer_no,3,1))&gt;0 and index('0123456789',substr(customer_no,4,1))&gt;0 and index('0123456789',substr(customer_no,5,1))&gt;0 and index('0123456789',substr(customer_no,6,1))&gt;0 and index('0123456789',substr(customer_no,7,1))&gt;0 and index('0123456789',substr(customer_no,8,1))&gt;0 and index('0123456789',substr(customer_no,9,1))&gt;0 and index('0123456789',substr(customer_no,10,1))&gt;0 and index('0123456789',substr(customer_no,11,1))&gt;0 and index('0123456789',substr(customer_no,12,1))&gt;0 then cast(customer_no as decimal(18)) else -1 end from CUSTOMER_TABLE ; </code></pre> <p>Be aware that if you put the check in the WHERE clause, depending on the plan Teradata might try to convert the varchar to numeric before applying the check, so it is better to have the CASE statement in the SELECT list.</p> http://teradataquestions.com/questions/1/what-udfs-would-you-like-to-see-written What UDFs would you like to see written? Carlos A. Ibarra 2009-09-30T04:05:02Z 2009-09-30T12:56:02Z <p>Teradata was missing a lot of the string manipulation and binary handling functions found on other DBMSs until they added the ability to write our own user defined functions. People wrote a lot of useful ones, most of which can be found in the <a href="http://www.teradata.com/DownloadCenter/Group116.aspx" rel="nofollow">Teradata Download Center</a>.</p> <p>I wish someone would write a regular expression search UDF. Maybe I'll tackle this some day.</p> <p>Which UDFs do you wish for? </p> http://teradataquestions.com/questions/200/variable-interval-size/201#201 Comment by Carlos A. Ibarra Carlos A. Ibarra 2010-08-26T03:35:59Z 2010-08-26T03:35:59Z If you have an integer number of days i, use current_timestamp - (interval '1' day) * i. http://teradataquestions.com/questions/73/teradata-sql-assistant-takes-forever-to-interrupt-large-answerset/140#140 Comment by Carlos A. Ibarra Carlos A. Ibarra 2010-05-12T17:48:27Z 2010-05-12T17:48:27Z I think the difference is that F9 submits all of your semicolon-separated statements as a single multi-statement request, while F5 submits them one at a time, waiting for results one by one. So there is still a need for F9 because there is no other way to specify that you want a multi-statement request in SQL Assistant. http://teradataquestions.com/questions/93/teradata-metadata-help Comment by Carlos A. Ibarra Carlos A. Ibarra 2010-03-17T23:43:29Z 2010-03-17T23:43:29Z The question is not clear but I think he wants the list of columns that the query is accessing. http://teradataquestions.com/questions/91/speeding-up-select-maxtimestamp-column-from-t-when-t-is-loaded-via-continuous/92#92 Comment by Carlos A. Ibarra Carlos A. Ibarra 2010-03-15T15:16:39Z 2010-03-15T15:16:39Z The query probably has to be WHERE CAST(ts as DATE) &gt;= CURRENT_DATE(), so that Teradata realizes it can use partition elimination. However, since the partitioning expression would not be part of the PI, partitioning might significantly affect the TPump performance. I have to check how many partitions would have data per each PI value. Thanks. http://teradataquestions.com/questions/71/order-by-based-on-case-sensitivity/72#72 Comment by Carlos A. Ibarra Carlos A. Ibarra 2010-02-11T03:17:02Z 2010-02-11T03:17:02Z Wow, nice trick with that CHAR2HEXINT(TRANSLATE()) thing! http://teradataquestions.com/questions/11/oracle-update-to-teradata-update-with-select-subquery/50#50 Comment by Carlos A. Ibarra Carlos A. Ibarra 2010-01-20T04:16:02Z 2010-01-20T04:16:02Z You cannot qualify the left hand part of the SET. Change set A.ORD_NBR to simply SET ORD_NBR without the A. http://teradataquestions.com/questions/53/rounding-increase-by-1/54#54 Comment by Carlos A. Ibarra Carlos A. Ibarra 2010-01-09T23:24:22Z 2010-01-09T23:24:22Z Try a larger number like decimal(10) then. http://teradataquestions.com/questions/51/order-by-issues/55#55 Comment by Carlos A. Ibarra Carlos A. Ibarra 2010-01-09T23:22:42Z 2010-01-09T23:22:42Z Then please accept the answer by clicking the checkmark icon next to it. http://teradataquestions.com/questions/56/query-in-select-list Comment by Carlos A. Ibarra Carlos A. Ibarra 2010-01-08T02:35:28Z 2010-01-08T02:35:28Z Can you try formatting your questions better by using the &quot;code sample&quot; button to mark embedded SQL code? Thanks. http://teradataquestions.com/questions/18/6760-invalid-timestamp/20#20 Comment by Carlos A. Ibarra Carlos A. Ibarra 2009-10-29T20:04:34Z 2009-10-29T20:04:34Z See my expanded explanation of output format. http://teradataquestions.com/questions/1/what-udfs-would-you-like-to-see-written/2#2 Comment by Carlos A. Ibarra Carlos A. Ibarra 2009-10-04T16:23:12Z 2009-10-04T16:23:12Z That's good news about Teradata's regular expressions plans. They may have to be extra careful to use an implementation that avoids pathological cases where the engine recurses a lot.