{"id":28621,"date":"2023-10-13T11:05:50","date_gmt":"2023-10-13T09:05:50","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/?p=28621"},"modified":"2023-10-13T11:05:52","modified_gmt":"2023-10-13T09:05:52","slug":"postgresql-17-support-for-at-local","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/","title":{"rendered":"PostgreSQL 17: Support for AT LOCAL"},"content":{"rendered":"\n<p>When it comes to conversions between time zones in PostgreSQL, there is already much you can do today. What PostgreSQL up to version 16 does not support, is the conversion to the local session&#8217;s time zone with &#8216;AT LOCAL&#8217;. Starting with PostgreSQL 17 this will be possible, as this functionality was just committed.<\/p>\n\n\n\n<p>Let&#8217;s have a look at how you can do the conversions from one time zone to another today. A very simple example is this one:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\npostgres=# show timezone;\n   TimeZone    \n---------------\n Europe\/Zurich\n(1 row)\n\npostgres=# select now();\n              now              \n-------------------------------\n 2023-10-13 10:44:01.527876+02\n(1 row)\n\npostgres=# select now() at time zone &#039;UTC&#039;;\n          timezone          \n----------------------------\n 2023-10-13 08:44:07.963283\n(1 row)\n\npostgres=# select now() at time zone &#039;UTC-2&#039;;\n          timezone          \n----------------------------\n 2023-10-13 10:44:46.859132\n(1 row)\n<\/pre><\/div>\n\n\n<p>This gives you the current time in &#8216;UTC&#8217; and &#8216;UTC-2&#8217; (which is my current time zone). A more readable format (at least for me) is to use the names of the time zones, e.g.:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\npostgres=# select now() at time zone &#039;Europe\/Zurich&#039;;\n          timezone          \n----------------------------\n 2023-10-13 10:46:18.676895\n(1 row)\n<\/pre><\/div>\n\n\n<p>All the available time zone names are listed in <a href=\"https:\/\/www.postgresql.org\/docs\/current\/view-pg-timezone-names.html\" target=\"_blank\" rel=\"noreferrer noopener\">pg_timezone_names<\/a>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\npostgres=# select * from pg_timezone_names limit 10;\n        name         | abbrev | utc_offset | is_dst \n---------------------+--------+------------+--------\n GMT0                | GMT    | 00:00:00   | f\n HST                 | HST    | -10:00:00  | f\n MST                 | MST    | -07:00:00  | f\n WET                 | WEST   | 01:00:00   | t\n Turkey              | +03    | 03:00:00   | f\n Cuba                | CDT    | -04:00:00  | t\n CST6CDT             | CDT    | -05:00:00  | t\n Canada\/Central      | CDT    | -05:00:00  | t\n Canada\/Newfoundland | NDT    | -02:30:00  | t\n Canada\/Eastern      | EDT    | -04:00:00  | t\n(10 rows)\n<\/pre><\/div>\n\n\n<p>If you want to know what the current time is in &#8220;Canada\/Central&#8221; this is as easy as this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\npostgres=# select now() at time zone &#039;Canada\/Central&#039;;\n          timezone          \n----------------------------\n 2023-10-13 03:50:15.374658\n(1 row)\n<\/pre><\/div>\n\n\n<p>Starting with PostgreSQL 17 you can in addition use the &#8216;AT LOCAL&#8217; syntax:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\npostgres=# set timezone to &#039;Europe\/Dublin&#039;;\nSET\npostgres=# select now() at local;\n          timezone          \n----------------------------\n 2023-10-13 09:58:10.712968\n(1 row)\n\npostgres=# select now() at local timezone;\n          timezone          \n----------------------------\n 2023-10-13 09:58:18.308281\n(1 row)\n\npostgres=# set timezone to &#039;Asia\/Calcutta&#039;;\nSET\npostgres=# select now() at local;\n         timezone         \n--------------------------\n 2023-10-13 14:28:39.4605\n(1 row)\n\npostgres=# select now() at local timezone;\n          timezone          \n----------------------------\n 2023-10-13 14:28:41.811844\n(1 row)\n<\/pre><\/div>\n\n\n<p>The word &#8220;timezone&#8221; is optional and can be skipped. For completeness: If you try this syntax in versions before 17, you&#8217;ll get this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\npostgres=# select version();\n                                                   version                                                    \n--------------------------------------------------------------------------------------------------------------\n PostgreSQL 16.0 on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit\n(1 row)\n\npostgres=# select now() at local timezone;\nERROR:  syntax error at or near &quot;local&quot;\nLINE 1: select now() at local timezone;\n                        ^\npostgres=# \n<\/pre><\/div>\n\n\n<p>Have a look at this <a href=\"https:\/\/www.postgresql.org\/message-id\/flat\/8e25dec4-5667-c1a5-6581-167d710c2182%40postgresfriends.org\">mail thread<\/a>, if you are interested in the discussion which finally resulted in this feature.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When it comes to conversions between time zones in PostgreSQL, there is already much you can do today. What PostgreSQL up to version 16 does not support, is the conversion to the local session&#8217;s time zone with &#8216;AT LOCAL&#8217;. Starting with PostgreSQL 17 this will be possible, as this functionality was just committed. Let&#8217;s have [&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],"tags":[77],"type_dbi":[],"class_list":["post-28621","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","category-database-management","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 17: Support for AT LOCAL - 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-17-support-for-at-local\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL 17: Support for AT LOCAL\" \/>\n<meta property=\"og:description\" content=\"When it comes to conversions between time zones in PostgreSQL, there is already much you can do today. What PostgreSQL up to version 16 does not support, is the conversion to the local session&#8217;s time zone with &#8216;AT LOCAL&#8217;. Starting with PostgreSQL 17 this will be possible, as this functionality was just committed. Let&#8217;s have [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-13T09:05:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-13T09:05:52+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-17-support-for-at-local\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/\"},\"author\":{\"name\":\"Daniel Westermann\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66\"},\"headline\":\"PostgreSQL 17: Support for AT LOCAL\",\"datePublished\":\"2023-10-13T09:05:50+00:00\",\"dateModified\":\"2023-10-13T09:05:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/\"},\"wordCount\":204,\"commentCount\":0,\"keywords\":[\"PostgreSQL\"],\"articleSection\":[\"Database Administration &amp; Monitoring\",\"Database management\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/\",\"name\":\"PostgreSQL 17: Support for AT LOCAL - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2023-10-13T09:05:50+00:00\",\"dateModified\":\"2023-10-13T09:05:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL 17: Support for AT LOCAL\"}]},{\"@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 17: Support for AT LOCAL - 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-17-support-for-at-local\/","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL 17: Support for AT LOCAL","og_description":"When it comes to conversions between time zones in PostgreSQL, there is already much you can do today. What PostgreSQL up to version 16 does not support, is the conversion to the local session&#8217;s time zone with &#8216;AT LOCAL&#8217;. Starting with PostgreSQL 17 this will be possible, as this functionality was just committed. Let&#8217;s have [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/","og_site_name":"dbi Blog","article_published_time":"2023-10-13T09:05:50+00:00","article_modified_time":"2023-10-13T09:05:52+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-17-support-for-at-local\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/"},"author":{"name":"Daniel Westermann","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66"},"headline":"PostgreSQL 17: Support for AT LOCAL","datePublished":"2023-10-13T09:05:50+00:00","dateModified":"2023-10-13T09:05:52+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/"},"wordCount":204,"commentCount":0,"keywords":["PostgreSQL"],"articleSection":["Database Administration &amp; Monitoring","Database management"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/","url":"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/","name":"PostgreSQL 17: Support for AT LOCAL - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2023-10-13T09:05:50+00:00","dateModified":"2023-10-13T09:05:52+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-17-support-for-at-local\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL 17: Support for AT LOCAL"}]},{"@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\/28621","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=28621"}],"version-history":[{"count":8,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/28621\/revisions"}],"predecessor-version":[{"id":28629,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/28621\/revisions\/28629"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=28621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=28621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=28621"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=28621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}