Questions tagged [truncate]

Data truncation is the automatic or deliberate shortening of data. A string, decimal number, or datestamp can be truncated to a shorter value. A data stream (such as a file or record set) can be truncated when either the entirety of the data is not needed or when it will be stored in a location too short to hold its entire length. No rounding occurs when numbers are truncated.

Data truncation may occur automatically, such as when a long string is written to a smaller buffer, or deliberately, when only a portion of the data is wanted. The truncation principles can be used in several different ways.

###Function Calls

Many data handling programs have built in methods or functions to handle truncation. Syntax will vary, but the principles are the same. Examples include:

  • Strings: TRUNC("This is a string.", 12) = This is a st
  • Decimals: TRUNC(3.14159, 2) = 3.14 or floor(3.14159) = 3
  • Dates: TRUNC(#7/4/2017 23:45#) = #7/4/2017 00:00#

###SQL Statement

In SQL, the TRUNCATE TABLE statement removes all rows from a table without invoking any triggered actions. The result of this operation quickly removes all data from a table, typically bypassing a number of integrity enforcing mechanisms. It was officially introduced in the SQL:2008 standard. In the SQL standard TRUNCATE TABLE is defined as a data manipulation language (DML) feature but database vendors often classify it as DDL for their own implementation-specific reasons.

The TRUNCATE TABLE mytable statement is logically (though not physically) equivalent to the DELETE FROM mytable statement (without a WHERE clause).

Datestamp values

Datestamps can be truncated. 2009-02-09 09:41:22 can be truncated, for example, to the:

  • year 2009-01-01 00:00:00
  • month 2009-02-01 00:00:00
  • day 2009-02-09 00:00:00
  • hour 2009-02-09 09:00:00

Related tags

References

Function Calls

SQL Statements

1585 questions
55
votes
7 answers

Truncating Query String & Returning Clean URL C# ASP.net

I would like to take the original URL, truncate the query string parameters, and return a cleaned up version of the URL. I would like it to occur across the whole application, so performing through the global.asax would be ideal. Also, I think a 301…
Chris
  • 621
  • 1
  • 5
  • 7
54
votes
5 answers

How to truncate a string in groovy?

How to truncate string in groovy? I used: def c = truncate("abscd adfa dasfds ghisgirs fsdfgf", 10) but getting error.
Srinath
  • 1,293
  • 3
  • 16
  • 25
48
votes
8 answers

How do I truncate a java string to fit in a given number of bytes, once UTF-8 encoded?

How do I truncate a java String so that I know it will fit in a given number of bytes storage once it is UTF-8 encoded?
Johan Lübcke
  • 19,666
  • 8
  • 38
  • 35
47
votes
13 answers

Truncating a file while it's being used (Linux)

I have a process that's writing a lot of data to stdout, which I'm redirecting to a log file. I'd like to limit the size of the file by occasionally copying the current file to a new name and truncating it. My usual techniques of truncating a file,…
Hobo
  • 7,536
  • 5
  • 40
  • 50
47
votes
4 answers

Truncate with condition

truncate ->this resets the entire table, is there a way via truncate to reset particular records/check conditions. For ex: i want to reset all the data and keep last 30 days inside the table. Thanks.
Sharpeye500
  • 8,775
  • 25
  • 95
  • 143
46
votes
4 answers

Android: Something better than android:ellipsize="end" to add "..." to truncated long Strings?

This property makes "short and very-long-word" to "short and" . But I want to have smth. like "short and very-lon..." Right now I truncate the String in Java code. However, thats based on the number of characters and not the actual length…
OneWorld
  • 17,512
  • 21
  • 86
  • 136
45
votes
10 answers

Truncate a string without ending in the middle of a word

I am looking for a way to truncate a string in Python that will not cut off the string in the middle of a word. For example: Original: "This is really awesome." "Dumb" truncate: "This is real..." "Smart" truncate: "This is…
Jack
  • 20,735
  • 11
  • 48
  • 48
43
votes
4 answers

MySQL: Truncate Table within Transaction?

I have an InnoDB table that needs to be re-populated every ten minutes within anywhere from 60k to 200k records. Our approach up to this point has been as follows: Turn off Autocommit Truncate the table Perform Select Queries & additional…
Brian Lacy
  • 18,785
  • 10
  • 55
  • 73
43
votes
6 answers

When an int is cast to a short and truncated, how is the new value determined?

Can someone clarify what happens when an integer is cast to a short in C? I'm using Raspberry Pi, so I'm aware that an int is 32 bits, and therefore a short must be 16 bits. Let's say I use the following C code for example: int x = 0x1248642; short…
buydadip
  • 8,890
  • 22
  • 79
  • 154
40
votes
14 answers

Lua: Rounding numbers and then truncate

Which is the best efficient way to round up a number and then truncate it (remove decimal places after rounding up)? for example if decimal is above 0.5 (that is, 0.6, 0.7, and so on), I want to round up and then truncate (case 1). Otherwise, I…
Willy
  • 9,848
  • 22
  • 141
  • 284
40
votes
4 answers

How to open (read-write) or create a file with truncation allowed?

I want to: open a file in read-write mode if it exists; create it if it doesn't exist; be able to truncate it anytime-anywhere. EDIT: with truncate I mean write until a position and discard the remaining part of the file, if present All this…
ceztko
  • 14,736
  • 5
  • 58
  • 73
38
votes
10 answers

Truncate Decimal number not Round Off

Possible Duplicate: c# - How do I round a decimal value to 2 decimal places (for output on a page) I want to truncate the decimals like below i.e. 2.22939393 -> 2.229 2.22977777 -> 2.229
ManojN
  • 855
  • 1
  • 11
  • 22
35
votes
5 answers

sqlite3 is chopping/cutting/truncating my text columns

I have values being cut off and would like to display the full values. Sqlite3 -column -header locations.dbs " select n.namelist, f.state, t.state from names n left join locations l on l.id = n.id left join statenames f on f.st = l.st left join…
Dan
  • 9,935
  • 15
  • 56
  • 66
35
votes
8 answers

Gremlin remove all Vertex

I know how to remove a vertex by id in Gremlin. But now I'm need to cleanup the database. How do I delete multiple vertices? Deleting 1 v is like this: ver = g.v(1) g.removeVertex(ver) I mean something like SQL TRUNCATE. How do you remove…
Aleksandrenko
  • 2,987
  • 6
  • 28
  • 34
34
votes
12 answers

SQL TRUNCATE DATABASE ? How to TRUNCATE ALL TABLES

I use SQL server 2008 R2. Is there a SQL command to empty the database, instead of having to truncate all 20 my tables? I just want to delete the data not the structure.
user609511
  • 4,091
  • 12
  • 54
  • 86