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
34
votes
1 answer

How do I create a new Joda DateTime truncated to the last hour?

I am pulling timestamps from a file that I want to create a new DateTime for, but I want to create the DateTime at the floor of the hour (or any Joda Period will do). How Can I do this?
WolfmanDragon
  • 7,851
  • 14
  • 49
  • 61
34
votes
11 answers

How to efficiently delete rows while NOT using Truncate Table in a 500,000+ rows table

Let's say we have table Sales with 30 columns and 500,000 rows. I would like to delete 400,000 in the table (those where "toDelete='1'"). But I have a few constraints : the table is read / written "often" and I would not like a long "delete" to…
Skippy Fastol
  • 1,745
  • 2
  • 17
  • 32
33
votes
9 answers

Truncating the first 100MB of a file in linux

I am referring to How can you concatenate two huge files with very little spare disk space? I'm in the midst of implementing the following: Allocate a sparse file of the combined size. Copy 100Mb from the end of the second file to the end of the…
CheeHow
  • 875
  • 4
  • 12
  • 27
33
votes
3 answers

Truncating a string in python

Someone gave me a syntax to truncate a string as follows: string = "My Text String" print string [0:3] # This is just an example I'm not sure what this is called (the string[0:3] syntax), so I've had a hard time trying to look it up on the…
Mike
  • 4,099
  • 17
  • 61
  • 83
32
votes
6 answers

Truncate NSDate (Zero-out time)

I want to generate a new NSDate with 0 hours, 0 minutes, and 0 seconds for time. The source date can be any random NSDate. Is there a way to achieve this? The documentation did not help me with this. Example Have: 2010-10-30 10:14:13 GMT Want:…
Benjamin
  • 323
  • 1
  • 3
  • 5
32
votes
4 answers

Is it possible to truncate date to Month with Java 8?

I want to get the milliseconds truncated to days, I can use Instant.now().truncatedTo(ChronoUnit.DAYS).toEpochMilli() But I can't truncate to ChronoUnit.MONTH (it throws an exception). Do I need use a Calendar?
EnverOsmanov
  • 625
  • 1
  • 7
  • 17
31
votes
5 answers

Truncating unicode so it fits a maximum size when encoded for wire transfer

Given a Unicode string and these requirements: The string be encoded into some byte-sequence format (e.g. UTF-8 or JSON unicode escape) The encoded string has a maximum length For example, the iPhone push service requires JSON encoding with a…
JasonSmith
  • 72,674
  • 22
  • 123
  • 149
31
votes
6 answers

Truncate multiple tables in one MySQL statement

Is there a possibility to truncate with one SQL statement, multiple tables? Like this: truncate table #OBJ_AvailabilityTraining, #OBJ_AvailabilityHoliday, #Dates_temp; Regards
user2206834
  • 379
  • 1
  • 5
  • 13
29
votes
5 answers

How do I indicate long text into a smaller fixed column with CSS?

How do I fit long text into a fixed width column where I have room for only one line of text? The text needs to be cut to a fixed width (lets say to 100px) and I would like to add dots "..." at the end. Something like this for example: Given…
Primoz Rome
  • 10,379
  • 17
  • 76
  • 108
28
votes
6 answers

How do I truncate a list in C#?

I know in python you can do something like myList[1:20] but is there anything similar in C#?
FinDev
  • 4,437
  • 6
  • 29
  • 29
27
votes
3 answers

Unwanted Decimal Truncation

My Model: public class Product { ... public decimal Fineness { get; set; } ... } Seeding the Database: new List { new Product { ..., Fineness = 0.757M, ... }, new Product { ..., Fineness =…
Gravy
  • 12,264
  • 26
  • 124
  • 193
26
votes
5 answers

Specifying maximum printf field width for numbers (truncating if necessary)?

You can truncate strings with a printf field-width specifier: printf("%.5s", "abcdefgh"); > abcde Unfortunately it does not work for numbers (replacing d with x is the same): printf("%2d", 1234); // for 34 printf("%.2d", 1234); // for…
Synetech
  • 9,643
  • 9
  • 64
  • 96
25
votes
3 answers

Truncate a string without cut in the middle of a word in rails

How can i truncate a text to the closest position with rails 3 whithout cut in the middle of a word? For exemple, I have the string : "Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Aenean eu leo quam. Pellentesque ornare sem…
Sebastien
  • 6,640
  • 14
  • 57
  • 105
24
votes
3 answers

Truncating Text in PHP?

I'm trying to truncate some text in PHP and have stumbled across this method (http://theodin.co.uk/blog/development/truncate-text-in-php-the-easy-way.html), which judging by the comments seems like a great easy-to-implement solution. The problem is…
realph
  • 4,481
  • 13
  • 49
  • 104
23
votes
6 answers

MySql - Create Table If Not Exists Else Truncate?

Here is the updated question: the current query is doing something like: $sql1 = "TRUNCATE TABLE fubar"; $sql2 = "CREATE TEMPORARY TABLE IF NOT EXISTS fubar SELECT id, name FROM barfu"; The first time the method containing this is run, it generates…
shmuel613
  • 1,702
  • 1
  • 15
  • 17