truncate

How to empty a SQL database?

只愿长相守 提交于 2019-11-29 00:54:19
问题 I'm searching for a simple way to delete all data from a database and keep the structure (table, relationship, etc...). I using postgreSQL but I think, if there a command to do that, it's not specific to postgres. Thanks, Damien 回答1: Dump the schema using pg_dump . drop the database, recreate it and load the schema. Dump you database schema (the -s tag) to a file: pg_dump -s -f db.dump DB-NAME Delete the database: dropdb DB-NAME Recreate it: createdb DB-NAME Restore the schema only: pg

Truncate multiple tables in one MySQL statement

南楼画角 提交于 2019-11-28 23:22:12
Is there a possibility to truncate with one SQL statement, multiple tables? Like this: truncate table #OBJ_AvailabilityTraining, #OBJ_AvailabilityHoliday, #Dates_temp; Regards IndoKnight No, you can only truncate a single table with TRUNCATE command. To truncate multiple tables you can use T-SQL and iterate through table names to truncate each at a time. DECLARE @delimiter CHAR(1), @tableList VARCHAR(MAX), @tableName VARCHAR(20), @currLen INT SET @delimiter = ',' SET @tableList = 'table1,table2,table3' WHILE LEN(@tableList) > 0 BEGIN SELECT @currLen = ( CASE charindex( @delimiter, @tableList )

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

限于喜欢 提交于 2019-11-28 21:57:49
问题 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 redirect would be in order as well. ie. in: www.website.com/default.aspx?utm_source=twitter&utm_medium=social-media out: www.website.com/default.aspx What would be the best way to achieve this? 回答1: System.Uri is your friend here. This has many

Scala Doubles, and Precision

♀尐吖头ヾ 提交于 2019-11-28 16:55:34
Is there a function that can truncate or round a Double? At one point in my code I would like a number like: 1.23456789 to be rounded to 1.23 You can use scala.math.BigDecimal : BigDecimal(1.23456789).setScale(2, BigDecimal.RoundingMode.HALF_UP).toDouble There are a number of other rounding modes , which unfortunately aren't very well documented at present (although their Java equivalents are ). Kaito Here's another solution without BigDecimals Truncate: (math floor 1.23456789 * 100) / 100 Round: (math rint 1.23456789 * 100) / 100 Or for any double n and precision p: def truncateAt(n: Double,

Truncate a string without ending in the middle of a word

て烟熏妆下的殇ゞ 提交于 2019-11-28 16:05:21
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 really..." I'm looking for a way to accomplish the "smart" truncate from above. I actually wrote a solution for this on a recent project of mine. I've compressed the majority of it down to be a little smaller. def smart_truncate(content, length=100, suffix='...'): if len(content) <= length: return content else: return ' '.join(content[:length+1].split(' ')[0:-1]) + suffix

Unix shell script to truncate a large file

旧街凉风 提交于 2019-11-28 15:54:23
问题 I am trying to write a Unix script which will truncate/empty a file which is continuously being written/open by an application when it reaches say 3GB of space. I know that the below command would do it : cp /dev/null [filename] But I am going to run this in an production environment automatically as a cron job - just posting here to see if you guys faced any issues while doing something similar to this. 回答1: Just to add another answer, : > filename : is a no-op in bash (POSIX-compliant), so

Truncate a decimal value in C++

为君一笑 提交于 2019-11-28 10:11:59
What's the easiest way to truncate a C++ float variable that has a value of 0.6000002 to a value of 0.6000 and store it back in the variable? First it is important to know that floating point numbers are approximated. See the link provided by @Greg Hewgill to understand why this problem is not fully solvable. But here are a couple of solutions to the problem that will probably meet your need: Probably the better method but less efficient: char sz[64]; double lf = 0.600000002; sprintf(sz, "%.4lf\n", lf); //sz contains 0.6000 double lf2 = atof(sz); //lf == 0.600000002; //lf2 == 0.6000 printf("%

Printing fieldsets in firefox

懵懂的女人 提交于 2019-11-28 09:13:42
I've been adding some new css to an existing project (using media="print") in the page header. It's going smooth and (for once!) IE is giving nice, expected results, but Firefox does not... The problem is that I have a fieldset which contains a lot of fields, and Firefox completely refuses (even in the latest version) to allow a page break inside the fieldset. This means anything that doesn't fit on one page is lost... I've found the bug acknowledged on the mozilla website which has been open for 3 years - https://bugzilla.mozilla.org/show_bug.cgi?id=471015 - but can't find any reasonable

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

狂风中的少年 提交于 2019-11-28 08:02:09
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 atomically (with a single open() call or simulating a single open() call) No single open modality seems to apply: r : obviously doesn't work; r+ : fails if the file doesn't exist; w: recreate the file if it exists; w+: recreate the file if it exists; a: can't read; a+: can't truncate. Some combinations I tried (rw, rw+, r+w, etc.) seems to not work either

mysql: how to truncate the length of a field

房东的猫 提交于 2019-11-28 07:21:26
问题 Alter table merry_parents change mobile mobile char(10). When I do the above I'm getting error: #1265 - Data truncated for column 'mobile' at row 2 How can I truncate my mobile field to char(10)? Currently it is char(12). 回答1: The error is telling you that there is data 12 characters long in row 2 (and probably others) so it's stopped the alter command to avoid losing data. Try updating your table using SUBSTRING() to shorten the column. It's unclear why you want to do this as you'll lose