{"id":27810,"date":"2025-05-07T06:18:43","date_gmt":"2025-05-07T06:18:43","guid":{"rendered":"http:\/\/www.withdata.com\/blog\/?p=27810"},"modified":"2026-03-07T02:02:46","modified_gmt":"2026-03-07T02:02:46","slug":"store-rtf-in-postgresql-text","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/clob\/store-rtf-in-postgresql-text.html","title":{"rendered":"Store RTF in PostgreSQL TEXT"},"content":{"rendered":"<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Rich_Text_Format\">RTF<\/a>(Rich Text Format) can be stored as PostgreSQL TEXT data.<\/p>\n<h2>1. PostgreSQL TEXT Type Overview<\/h2>\n<p>PostgreSQL TEXT has no character length limits (disk-bound) and natively supports large character storage.<\/p>\n<p>Compatible with VARCHAR syntax, no special initialization required, extremely simple to operate.<\/p>\n<h2>2. Pure SQL Implementation Steps<\/h2>\n<h3>Step 1: Create Table with TEXT Field<\/h3>\n<pre>CREATE TABLE RTF_DOCS (\r\n    DOC_ID SERIAL PRIMARY KEY, -- Auto-increment primary key\r\n    DOC_NAME VARCHAR(100) NOT NULL,\r\n    RTF_CONTENT TEXT NOT NULL, -- Core field for RTF storage\r\n    CREATE_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP\r\n);\r\n<\/pre>\n<h3>Step 2: Insert RTF Text into TEXT Field<\/h3>\n<pre>-- Method 1: Insert short RTF text directly\r\nINSERT INTO RTF_DOCS (DOC_NAME, RTF_CONTENT)\r\nVALUES (\r\n    'test.rtf',\r\n    '{\\\\rtf1\\\\ansi\\\\deff0 {\\\\fonttbl {\\\\f0 Calibri;}} \\\\pard\\\\f0\\\\fs22 PostgreSQL RTF Test\\\\par}'\r\n);\r\n\r\n-- Method 2: Import external RTF file (psql command line)\r\n-- 1. Log in to psql: psql -U username -d your_database\r\n-- 2. Import file content with the following commands\r\n\\set rtf_content `cat \/path\/to\/test.rtf` -- Read local RTF file\r\nINSERT INTO RTF_DOCS (DOC_NAME, RTF_CONTENT) VALUES ('imported.rtf', :'rtf_content');\r\n<\/pre>\n<h3>Step 3: Query\/Edit RTF Content<\/h3>\n<pre>-- Query full RTF content\r\nSELECT DOC_NAME, RTF_CONTENT FROM RTF_DOCS WHERE DOC_ID = 1;\r\n\r\n-- Truncate RTF preview (first 180 characters)\r\nSELECT DOC_NAME, SUBSTRING(RTF_CONTENT FROM 1 FOR 180) AS RTF_PREVIEW FROM RTF_DOCS;\r\n\r\n-- Update RTF content\r\nUPDATE RTF_DOCS \r\nSET RTF_CONTENT = '{\\\\rtf1\\\\ansi\\\\deff0 \\\\pard\\\\f0\\\\fs28 Updated PostgreSQL RTF\\\\par}'\r\nWHERE DOC_ID = 1;\r\n<\/pre>\n<h3>Step 4: Delete RTF Record<\/h3>\n<pre>DELETE FROM RTF_DOCS WHERE DOC_ID = 2;\r\n<\/pre>\n<h2>3. Simplify PostgreSQL TEXT RTF Management with DBBlobEditor<\/h2>\n<p><a rel=\"noopener\" href=\"\/dbblobeditor\/\" target=\"_blank\">DBBlobEditor<\/a> optimizes RTF handling for PostgreSQL TEXT fields:<\/p>\n<ul>\n<li>\n<h3>View \/ Edit RTF<\/h3>\n<p><a href=\"\/blog\/pglobeditor\/view-rtf-data-in-postgresql-text-read-display-rtf-from-postgresql-text-column.html\">Visually browse and edit RTF content in PostgreSQL TEXT fields<\/a> without command-line tools.<a rel=\"noopener\" href=\"\/images\/lobeditor\/blob-rtf.png\" target=\"_blank\">?<\/a><\/li>\n<li>\n<h3>Insert RTF into PostgreSQL TEXT<\/h3>\n<p><a href=\"\/blog\/pglobeditor\/import-rtf-to-postgresql-text.html\">Bulk import RTF into PostgreSQL TEXT<\/a> with few clicks.<\/li>\n<li>\n<h3>Extract PostgreSQL TEXT to RTF<\/h3>\n<p><a href=\"\/blog\/pglobeditor\/postgresql-export-text-to-rtf.html\">Bulk export PostgreSQL TEXT to RTF files<\/a> visually, avoiding complex scripts.<\/li>\n<\/ul>\n<h2>4. Notes<\/h2>\n<ul>\n<li>Ensure files are UTF-8 encoded when reading with psql&#8217;s \\set command to avoid garbled text<\/li>\n<li>PostgreSQL TEXT fields support full-text search; create GIN indexes to optimize RTF content queries<\/li>\n<li>No character length limits, but keep single records under 1GB to avoid performance issues<\/li>\n<\/ul>\n<hr \/>\n<h3>Related Guides<\/h3>\n<ul>\n<li><a href=\"\/blog\/clob\/store-rtf-in-clob.html\">Store RTF in CLOB: Complete Guide for Character Fields Across Databases<\/a><\/li>\n<li><a href=\"\/blog\/clob\/store-rtf-in-db2-clob.html\">Store RTF in DB2 CLOB<\/a><\/li>\n<li><a href=\"\/blog\/clob\/store-rtf-in-oracle-clob.html\">Store RTF in Oracle CLOB<\/a><\/li>\n<li><a href=\"\/blog\/clob\/store-rtf-in-sql-server-nvarcharmax.html\">Store RTF in SQL Server NVARCHAR(MAX)<\/a><\/li>\n<li><a href=\"\/blog\/clob\/store-rtf-in-mysql-text.html\">Store RTF in MySQL TEXT<\/a><\/li>\n<li><a href=\"\/blog\/clob\/store-rtf-in-sqlite-text.html\">Store RTF in SQLite TEXT<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>RTF(Rich Text Format) can be stored as PostgreSQL TEXT data. 1. PostgreSQL TEXT Type Overview PostgreSQL TEXT has no character length limits (disk-bound) and natively supports large character storage. Compatible with VARCHAR syntax, no special initialization required, extremely simple to operate. 2. Pure SQL Implementation Steps Step 1: Create Table with TEXT Field CREATE TABLE [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4526],"tags":[100,1370,2106,176],"class_list":["post-27810","post","type-post","status-publish","format-standard","hentry","category-clob","tag-clob","tag-postgresql","tag-rtf","tag-text"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/27810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/comments?post=27810"}],"version-history":[{"count":5,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/27810\/revisions"}],"predecessor-version":[{"id":45455,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/27810\/revisions\/45455"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=27810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=27810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=27810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}