I currently have a Postgres 8.4 database containing a varchar (10000) column. I would like to change this to varchar (255) and truncate any data that is too long. How can i do this?
Something like ALTER TABLE t ALTER COLUMN c TYPE VARCHAR(255) USING SUBSTR(c, 1, 255)
ALTER TABLE t ALTER COLUMN c TYPE VARCHAR(255) USING SUBSTR(c, 1, 255)
1) Update the column data using the substring method to truncate it
update t set col = substring(col from 1 for 255)
2) Then change the table column
alter table t alter column col type varchar(255)
Docs here http://www.postgresql.org/docs/8.4/static/sql-altertable.html
BEGIN; UPDATE table SET column = CAST(column as varchar(255)); ALTER TABLE table ALTER COLUMN column TYPE varchar(255); --not sure on this line. my memory is a bit sketchy COMMIT;
Source: https://habr.com/ru/post/1304417/More articles:Delphi 2010 and .net - .netWindows / C ++: how to use a COM DLL that is not registered - c ++https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1304414/add-chapters-to-m4a-mp4-files&usg=ALkJrhj5XJDGPzS7PnpmABrBxeBJKNsH1gWhere does Xcode Organizer store iPhone screenshots? - iphoneWhat is the right stage of using Google Guice in production on an application server? - javaCreate hyperlink in django template of object with space - htmlSlow query with unexpected index scan - performanceWhat is the difference between ruby irb prompt modes? - ruby | fooobar.comIs there an Objective-Java integration library? - javaRecursion in Java Enumerations? - javaAll Articles