{"id":43920,"date":"2026-04-15T06:41:59","date_gmt":"2026-04-15T04:41:59","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/?p=43920"},"modified":"2026-04-14T06:44:47","modified_gmt":"2026-04-14T04:44:47","slug":"postgresql-19-json-format-for-copy-to","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/","title":{"rendered":"PostgreSQL 19: json format for &#8220;copy to&#8221;"},"content":{"rendered":"\n<p>PostgreSQL already has impressive support for working with data in <a href=\"https:\/\/www.json.org\/json-en.html\" target=\"_blank\" rel=\"noreferrer noopener\">json<\/a> format. If you look at the <a href=\"https:\/\/www.postgresql.org\/docs\/current\/datatype-json.html\">jsonb<\/a> data type and all the <a href=\"https:\/\/www.postgresql.org\/docs\/current\/functions-json.html\">built-in functions and operators<\/a> you can use, there is so much you can do with it by default. Starting with PostgreSQL 19 there is one feature more when it comes to working with data in json format.<\/p>\n\n\n\n<p>&#8220;<a href=\"https:\/\/www.postgresql.org\/docs\/current\/sql-copy.html\">COPY<\/a>&#8221; already is quite powerful and the fastest way to get data in and out of PostgreSQL (you may read some previous posts about copy <a href=\"https:\/\/www.dbi-services.com\/blog\/postgresql-17-copy-and-save_error_to\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>, <a href=\"https:\/\/www.dbi-services.com\/blog\/postgresql-18-reject_limit-for-copy\/\">here<\/a>, and <a href=\"https:\/\/www.dbi-services.com\/blog\/postgresql-17-track-skipped-rows-from-copy-in-pg_stat_progress_copy\/\">here<\/a>). <\/p>\n\n\n\n<p>As usual lets start with a simple table:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; highlight: [1,3]; title: ; notranslate\" title=\"\">\npostgres=# create table t ( a int primary key, b text );\nCREATE TABLE\npostgres=# insert into t select i, md5(i::text) from generate_series(1,1000000) i;\nINSERT 0 1000000\n<\/pre><\/div>\n\n\n<p>To get that data out in text format you might simply do this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; highlight: [1,3]; title: ; notranslate\" title=\"\">\npostgres=# copy t to &#039;\/var\/tmp\/t&#039;;\nCOPY 1000000\npostgres=# \\! head \/var\/tmp\/t\n1       c4ca4238a0b923820dcc509a6f75849b\n2       c81e728d9d4c2f636f067f89cc14862c\n3       eccbc87e4b5ce2fe28308fd9f2a7baf3\n4       a87ff679a2f3e71d9181a67b7542122c\n5       e4da3b7fbbce2345d7772b0674a318d5\n6       1679091c5a880faf6fb5e6087eb1b2dc\n7       8f14e45fceea167a5a36dedd4bea2543\n8       c9f0f895fb98ab9159f51fd0297e236d\n9       45c48cce2e2d7fbdea1afc51c7c6ad26\n10      d3d9446802a44259755d38e6d163e820\n<\/pre><\/div>\n\n\n<p>Starting with PostgreSQL 19 you can do the same in json format:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; highlight: [1,3]; title: ; notranslate\" title=\"\">\npostgres=# copy t to &#039;\/var\/tmp\/t1&#039; with (format json);\nCOPY 1000000\npostgres=# \\! head \/var\/tmp\/t1\n{&quot;a&quot;:1,&quot;b&quot;:&quot;c4ca4238a0b923820dcc509a6f75849b&quot;}\n{&quot;a&quot;:2,&quot;b&quot;:&quot;c81e728d9d4c2f636f067f89cc14862c&quot;}\n{&quot;a&quot;:3,&quot;b&quot;:&quot;eccbc87e4b5ce2fe28308fd9f2a7baf3&quot;}\n{&quot;a&quot;:4,&quot;b&quot;:&quot;a87ff679a2f3e71d9181a67b7542122c&quot;}\n{&quot;a&quot;:5,&quot;b&quot;:&quot;e4da3b7fbbce2345d7772b0674a318d5&quot;}\n{&quot;a&quot;:6,&quot;b&quot;:&quot;1679091c5a880faf6fb5e6087eb1b2dc&quot;}\n{&quot;a&quot;:7,&quot;b&quot;:&quot;8f14e45fceea167a5a36dedd4bea2543&quot;}\n{&quot;a&quot;:8,&quot;b&quot;:&quot;c9f0f895fb98ab9159f51fd0297e236d&quot;}\n{&quot;a&quot;:9,&quot;b&quot;:&quot;45c48cce2e2d7fbdea1afc51c7c6ad26&quot;}\n{&quot;a&quot;:10,&quot;b&quot;:&quot;d3d9446802a44259755d38e6d163e820&quot;}\n<\/pre><\/div>\n\n\n<p>Specifying a SQL is also supported:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; highlight: [1,3]; title: ; notranslate\" title=\"\">\npostgres=# copy (select a from t) to &#039;\/var\/tmp\/t1&#039; with (format json);\nCOPY 1000000\npostgres=# \\! head \/var\/tmp\/t1\n{&quot;a&quot;:1}\n{&quot;a&quot;:2}\n{&quot;a&quot;:3}\n{&quot;a&quot;:4}\n{&quot;a&quot;:5}\n{&quot;a&quot;:6}\n{&quot;a&quot;:7}\n{&quot;a&quot;:8}\n{&quot;a&quot;:9}\n{&quot;a&quot;:10}\n<\/pre><\/div>\n\n\n<p>As noted in the <a href=\"https:\/\/git.postgresql.org\/gitweb\/?p=postgresql.git;a=commitdiff;h=7dadd38cda95bf5bc0c4715d9ab71766d1693379\">commit message<\/a> there are some options which are not compatible with the json format:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>HEADER<\/li>\n\n\n\n<li>DEFAULT<\/li>\n\n\n\n<li>NULL<\/li>\n\n\n\n<li>DELIMITER<\/li>\n\n\n\n<li>FORCE QUOTE<\/li>\n\n\n\n<li>FORCE NOT NULL<\/li>\n\n\n\n<li>and FORCE NULL<\/li>\n<\/ul>\n\n\n\n<p>Also not supported (currently) is &#8220;copy from&#8221;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PostgreSQL already has impressive support for working with data in json format. If you look at the jsonb data type and all the built-in functions and operators you can use, there is so much you can do with it by default. Starting with PostgreSQL 19 there is one feature more when it comes to working [&hellip;]<\/p>\n","protected":false},"author":29,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229,198,1],"tags":[77],"type_dbi":[],"class_list":["post-43920","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","category-database-management","category-non-classifiee","tag-postgresql"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>PostgreSQL 19: json format for &quot;copy to&quot; - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL 19: json format for &quot;copy to&quot;\" \/>\n<meta property=\"og:description\" content=\"PostgreSQL already has impressive support for working with data in json format. If you look at the jsonb data type and all the built-in functions and operators you can use, there is so much you can do with it by default. Starting with PostgreSQL 19 there is one feature more when it comes to working [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-04-15T04:41:59+00:00\" \/>\n<meta name=\"author\" content=\"Daniel Westermann\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@westermanndanie\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Daniel Westermann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/\"},\"author\":{\"name\":\"Daniel Westermann\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66\"},\"headline\":\"PostgreSQL 19: json format for &#8220;copy to&#8221;\",\"datePublished\":\"2026-04-15T04:41:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/\"},\"wordCount\":169,\"commentCount\":0,\"keywords\":[\"PostgreSQL\"],\"articleSection\":[\"Database Administration &amp; Monitoring\",\"Database management\",\"Non classifi\u00e9(e)\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/\",\"name\":\"PostgreSQL 19: json format for \\\"copy to\\\" - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2026-04-15T04:41:59+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL 19: json format for &#8220;copy to&#8221;\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66\",\"name\":\"Daniel Westermann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"caption\":\"Daniel Westermann\"},\"description\":\"Daniel Westermann is Principal Consultant and Technology Leader Open Infrastructure at dbi services. He has more than 15 years of experience in management, engineering and optimization of databases and infrastructures, especially on Oracle and PostgreSQL. Since the beginning of his career, he has specialized in Oracle Technologies and is Oracle Certified Professional 12c and Oracle Certified Expert RAC\/GridInfra. Over time, Daniel has become increasingly interested in open source technologies, becoming \u201cTechnology Leader Open Infrastructure\u201d and PostgreSQL expert. \u00a0Based on community or EnterpriseDB tools, he develops and installs complex high available solutions with PostgreSQL. He is also a certified PostgreSQL Plus 9.0 Professional and a Postgres Advanced Server 9.4 Professional. He is a regular speaker at PostgreSQL conferences in Switzerland and Europe. Today Daniel is also supporting our customers on AWS services such as AWS RDS, database migrations into the cloud, EC2 and automated infrastructure management with AWS SSM (System Manager). He is a certified AWS Solutions Architect Professional. Prior to dbi services, Daniel was Management System Engineer at LC SYSTEMS-Engineering AG in Basel. Before that, he worked as Oracle Developper &amp;\u00a0Project Manager at Delta Energy Solutions AG in Basel (today Powel AG). Daniel holds a diploma in Business Informatics (DHBW, Germany). His branch-related experience mainly covers the pharma industry, the financial sector, energy, lottery and telecommunications.\",\"sameAs\":[\"https:\/\/x.com\/westermanndanie\"],\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/daniel-westermann\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"PostgreSQL 19: json format for \"copy to\" - dbi Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL 19: json format for \"copy to\"","og_description":"PostgreSQL already has impressive support for working with data in json format. If you look at the jsonb data type and all the built-in functions and operators you can use, there is so much you can do with it by default. Starting with PostgreSQL 19 there is one feature more when it comes to working [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/","og_site_name":"dbi Blog","article_published_time":"2026-04-15T04:41:59+00:00","author":"Daniel Westermann","twitter_card":"summary_large_image","twitter_creator":"@westermanndanie","twitter_misc":{"Written by":"Daniel Westermann","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/"},"author":{"name":"Daniel Westermann","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66"},"headline":"PostgreSQL 19: json format for &#8220;copy to&#8221;","datePublished":"2026-04-15T04:41:59+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/"},"wordCount":169,"commentCount":0,"keywords":["PostgreSQL"],"articleSection":["Database Administration &amp; Monitoring","Database management","Non classifi\u00e9(e)"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/","url":"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/","name":"PostgreSQL 19: json format for \"copy to\" - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2026-04-15T04:41:59+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-19-json-format-for-copy-to\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL 19: json format for &#8220;copy to&#8221;"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66","name":"Daniel Westermann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","caption":"Daniel Westermann"},"description":"Daniel Westermann is Principal Consultant and Technology Leader Open Infrastructure at dbi services. He has more than 15 years of experience in management, engineering and optimization of databases and infrastructures, especially on Oracle and PostgreSQL. Since the beginning of his career, he has specialized in Oracle Technologies and is Oracle Certified Professional 12c and Oracle Certified Expert RAC\/GridInfra. Over time, Daniel has become increasingly interested in open source technologies, becoming \u201cTechnology Leader Open Infrastructure\u201d and PostgreSQL expert. \u00a0Based on community or EnterpriseDB tools, he develops and installs complex high available solutions with PostgreSQL. He is also a certified PostgreSQL Plus 9.0 Professional and a Postgres Advanced Server 9.4 Professional. He is a regular speaker at PostgreSQL conferences in Switzerland and Europe. Today Daniel is also supporting our customers on AWS services such as AWS RDS, database migrations into the cloud, EC2 and automated infrastructure management with AWS SSM (System Manager). He is a certified AWS Solutions Architect Professional. Prior to dbi services, Daniel was Management System Engineer at LC SYSTEMS-Engineering AG in Basel. Before that, he worked as Oracle Developper &amp;\u00a0Project Manager at Delta Energy Solutions AG in Basel (today Powel AG). Daniel holds a diploma in Business Informatics (DHBW, Germany). His branch-related experience mainly covers the pharma industry, the financial sector, energy, lottery and telecommunications.","sameAs":["https:\/\/x.com\/westermanndanie"],"url":"https:\/\/www.dbi-services.com\/blog\/author\/daniel-westermann\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/43920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=43920"}],"version-history":[{"count":4,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/43920\/revisions"}],"predecessor-version":[{"id":43924,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/43920\/revisions\/43924"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=43920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=43920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=43920"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=43920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}