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
10
votes
2 answers

Is it possible to delete bytes from the beginning of a file?

I know that I can efficiently truncate a file and remove bytes from the end of the file. Is there a corresponding efficient way to truncate files by deleting content from the beginning of the file to a point in the middle of the file?
TheDude
  • 3,045
  • 4
  • 46
  • 95
10
votes
2 answers

Using the HTML5 FileWriter truncate() method?

I'm experimenting with the HTML5 File API, and I'm needing to use a method which I don't know enough about (simply because it's hardly documented anywhere). I'm talking about the FileWriter truncate() method, and I know it does what I need to do.…
caleb531
  • 4,111
  • 6
  • 31
  • 41
10
votes
3 answers

shrink (truncate) file from beginning on linux

Is it possible in Linux (and/or on other Unix) 'shrink' file from beginning? I'd like to use it for persistent queue (no existing implementation suits my needs). From end of file I guess it's possible with truncate().
woky
  • 4,686
  • 9
  • 36
  • 44
10
votes
7 answers

Rails truncate helper with link as omit text

I'm quite long description that I want to truncate using truncate helper. So i'm using the: truncate article.description, :length => 200, :omission => ' ...' The problem is that I want to use more as a clickable link so in theory I could use…
Jakub Troszok
  • 99,267
  • 11
  • 41
  • 53
10
votes
4 answers

How to recover data from truncated table

while going though sql server interview question in book of mr. shiv prashad koirala. i got to know that, even after using truncate table command the data can be recovered. please tell me how can we recover data when data is deleted using 'delete'…
Dr. Rajesh Rolen
  • 14,029
  • 41
  • 106
  • 178
10
votes
2 answers

How to truncate a join table in rails?

To truncate an ActiveRecord table, I can do Category.destroy_all or Post.destroy_all How does one go about truncating a categories_post table?
maček
  • 76,434
  • 37
  • 167
  • 198
10
votes
4 answers

How do I truncate a string while converting to bytes in C#?

I would like to put a string into a byte array, but the string may be too big to fit. In the case where it's too large, I would like to put as much of the string as possible into the array. Is there an efficient way to find out how many characters…
TimK
  • 7,438
  • 10
  • 40
  • 47
10
votes
3 answers

Truncating HTML content at the end of text blocks (block elements)

Mainly when we shorten/truncate textual content we usually just truncate it at specific character index. That's already complicated in HTML anyway, but I want to truncate my HTML content (generated using content-editable div) using different…
Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
10
votes
4 answers

How to find that the content is truncated?

I'm trying to build a blog app and the problem is when I use tag 'truncatewords_html' in my template to truncate posts longer than specified number of words, I need to link to complete post by some title like 'read more...' after truncation. So I…
sadegh
  • 103
  • 5
10
votes
8 answers

Truncated Data when Importing from Excel to an Access Memo Field

Access is truncating the data in a couple Memo fields when I am appending an Excel file. The field in the Access table is already set as a Memo type. I believe the problem is that I do not have any entries in the first few rows of some of the memo…
RBSt
  • 143
  • 1
  • 3
  • 10
10
votes
4 answers

How to check if NSTextfield is already truncating the text (... at the end)

I've searched around on how to perform this but I can't find any answer. I'd like to know if my NSTextfield is already truncating the text (... at the end) without having to check the length of its stringValue. I need to do this to know if I should…
Pedro Vieira
  • 3,330
  • 3
  • 41
  • 76
10
votes
5 answers

Rails: Smart text truncation

I wonder if there's a plugin to enable a sort of smart truncation. I need to truncate my text with a precision of a word or of a sentence. For example: Post.my_message.smart_truncate( "Once upon a time in a world far far away. And they found…
oldhomemovie
  • 14,621
  • 13
  • 64
  • 99
9
votes
2 answers

ruby on rails log file to big -> remove params from it

i made a distribuited real-time system in RoR, it's compose by 2 machine. PC A: take images from a Camera and send these to the second PC. So this machine send every second an http request with the image in the params. PC B - the server: save the…
Dabidi
  • 397
  • 5
  • 14
9
votes
4 answers

Fast float to int conversion (truncate)

I'm looking for a way to truncate a float into an int in a fast and portable (IEEE 754) way. The reason is because in this function 50% of the time is spent in the cast: float fm_sinf(float x) { const float a = …
orlp
  • 112,504
  • 36
  • 218
  • 315
9
votes
7 answers

Trim string to length ignoring HTML

This problem is a challenging one. Our application allows users to post news on the homepage. That news is input via a rich text editor which allows HTML. On the homepage we want to only display a truncated summary of the news item. For example,…
steve_c
  • 6,235
  • 4
  • 32
  • 42