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
8
votes
5 answers

How do I rewrite my MySQL update statement to eliminate "Truncated incorrect INTEGER value" warnings?

I'm using MySQL 5.5.37. I want to eliminate the warnings from my update statement, which are shown below ... update resource r set grade_id = convert(substring_index(substring_index( r.description, 'Grade ', -1), ' ', 1),…
Dave
  • 15,639
  • 133
  • 442
  • 830
8
votes
2 answers

How to find out width of truncated UILabel text

I have UILabel, which contains dynamic text. Sometimes text is too long to be shown and thus automagically truncated. How do I find out width of the visible part of truncated text? sizeThatFits returns length of untruncated text, so at the moment I…
JOM
  • 8,139
  • 6
  • 78
  • 111
8
votes
5 answers

Truncate string in Rails: "..." showing up on strings at length

I'm currently trying to truncate any strings greater than 65 characters. My code is <%= truncate(title.html_safe, length:65) %> It works great for titles longer than 65 characters. But titles that are exactly 65 character still get…
AllieCat
  • 3,890
  • 10
  • 31
  • 45
8
votes
2 answers

Does TRUNCATE TABLE grows up transaction log?

I have read that one of the differences between DELETE and TRUNCATE TABLE in Sql is the TRUNCATE operation cannot be rolled back and no triggers will be fired (as written in this site for example) : QUESTION: Does this mean that when I TRUNcATE…
pencilCake
  • 51,323
  • 85
  • 226
  • 363
8
votes
1 answer

Can't truncate MySQL table, while being able to delete all the records

I'm a very beginner to relations, so this may sound dumb. But, what is the difference (in MySQL) between truncating a table and removing all the records (this answer says only about performance)? I was playing (in phpMyAdmin) with one of my test…
trejder
  • 17,148
  • 27
  • 124
  • 216
8
votes
1 answer

Automatic TRUNCATE table in MySQL

I am looking for a way to automatically clean table in MySQL once per day. Is this possible without using cron? The best solution would be a trigger, but any solution is applicable.
SoundwaveUwU
  • 138
  • 1
  • 2
  • 12
8
votes
4 answers

Truncate a multibyte String to n chars

I am trying to get this method in a String Filter working: public function truncate($string, $chars = 50, $terminator = ' …'); I'd expect this $in = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYXZ1234567890"; $out =…
Gordon
  • 312,688
  • 75
  • 539
  • 559
8
votes
2 answers

How to truncate a string to fit in a container?

There are a lot of questions (EG: 1, 2, 3, 4, 5) asking how you can truncate a string to a desired amount of characters. But I want a piece of text truncated to fit in a container. (IE: crop the string by it's width in pixels, not characters). This…
Jordy
  • 1,816
  • 16
  • 29
8
votes
3 answers

How to rollback delete command without using transaction

How to rollback delete command without using transaction ? if we can't , then what's the difference between Truncate & delete ?
Nim J
  • 993
  • 2
  • 9
  • 15
8
votes
4 answers

Using JavaScript to truncate text to a certain size (8 KB)

I'm using the Zemanta API, which accepts up to 8 KB of text per call. I'm extracting the text to send to Zemanta from Web pages using JavaScript, so I'm looking for a function that will truncate my text at exactly 8 KB. Zemanta should do this…
Bungle
  • 19,392
  • 24
  • 79
  • 106
8
votes
5 answers

Truncating the end of a string in R after a character that can be present zero or more times

I have the following data: temp<-c("AIR BAGS:FRONTAL" ,"SERVICE BRAKES HYDRAULIC:ANTILOCK", "PARKING BRAKE:CONVENTIONAL", "SEATS:FRONT ASSEMBLY:POWER ADJUST", "POWER TRAIN:AUTOMATIC TRANSMISSION", "SUSPENSION", "ENGINE AND ENGINE…
Tony M.
  • 155
  • 1
  • 2
  • 7
7
votes
2 answers

How to force Text::CSV to store number as text?

I am writing some perl code to create a .csv file from records in the database, using the Text::CSV module. Occasionally, one or more of the fields in my table will contain multiple repeating 0s, which will write to the CSV as a single 0. I'm trying…
ComputersAreNeat
  • 175
  • 1
  • 1
  • 11
7
votes
3 answers

TextView: Get it to truncate without respect to spaces between words

How do you configure a TextView to truncate in the middle of a word? So if I have text="Some Text" I want it to show as "Some Te" assuming the width supports that. What instead I'm seeing is "Some"; its truncating the entire word "Text" even though…
Fraggle
  • 8,607
  • 7
  • 54
  • 86
7
votes
6 answers

How can I elliptically truncate text in golang?

I'd like to be able to cleanly cut a paragraph larger than certain number of characters without cutting a word in the middle. So for example this: It is a long established fact that a reader will be distracted by the readable content of a page…
Smn
  • 145
  • 1
  • 3
  • 9
7
votes
1 answer

Importing a CSV with different row widths into Incanter?

I'm trying to import a CSV file with rows of many different lengths into Incanter using the read-dataset function. Unfortunately, it appears to truncate the rows down to the length of the first row. Short of reordering the dataset, or searching for…