Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iCxU1-0000u6-HK for pgsql-general@arkaria.postgresql.org; Wed, 25 Sep 2019 02:56:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iCxU0-0001x1-2I for pgsql-general@arkaria.postgresql.org; Wed, 25 Sep 2019 02:56:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iCxTz-0001tq-NN for pgsql-general@lists.postgresql.org; Wed, 25 Sep 2019 02:56:47 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iCxTx-0007Pb-J6 for pgsql-general@lists.postgresql.org; Wed, 25 Sep 2019 02:56:47 +0000 Received: by mail-pf1-x444.google.com with SMTP id y72so2455478pfb.12 for ; Tue, 24 Sep 2019 19:56:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=9iV5Tg2VxZOfqVssUtOj4FCo6Eh9vyua8zB1T/Xs8AA=; b=nFN8R+LEs4X1SdNtcunTOBbrMDPWDdXPCou46NerVTfsVJlNVk7WQvtl9RcNm6Ppyt BuNu3zBuRLesB00zAyRO2R/vaPWrFmxOfrPzCmYkqmNJBKnf9aNK1U51i55ff8Mig8Lv guoahlKqE4XDU9WV7v+y+DBzfn8RW130cfvv1n1Znh6iPLNdp2N1EB8Aqp3e7nHG24L2 JrwruwMdLaYaEZO1hlll9EHgGqfumvk61EO9GUaAC4pEFD0RDz/d14e8n/g2Dkn08hcu RDPxjAjWQqzQF50cP6PLitDmyndJV7UUvdiJnAIvdXi/yBWvhux1kDjJi2fI3ZhCrb2w mmkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=9iV5Tg2VxZOfqVssUtOj4FCo6Eh9vyua8zB1T/Xs8AA=; b=X0z4f6DLoYaprKxu1KukpG2uWIZQWHyxI8cvk0qKPCB7cufJGdG3XmVGDXJeEQw0VM 5P15kFRycMdnjHJyZyJjoA4tr2IhhpE+5A88uLc0T7m9R162Ns3tnVkL/3RlNVz0eyPZ mRYXC6QOVE2KkAQRyJeCvjoti9mPbXi6Xt11mKg71JY+t1GM4Xq2GecMULXnj+k/KkBS 8eJyPWBx0e6axsx8gWxsz8WFSsQQfzdiaTL5/t4Hivb4GPkPykP4EzDr50e4atS5sEM0 0pk5Y54PzOQQs+3pxSJLJazOLUd+Tc4bsB4Q3wm31nev2QqXIQOFH/jhA0Z/oJwQEW9u rkdA== X-Gm-Message-State: APjAAAU6FS6gxN162Kpt3OomyJrm/VN7H7FLqM0NPhvPMD/Wb14Z/4tq NCruUy10Ebj7Rl/IHIvWX9RIWdn5dZo= X-Google-Smtp-Source: APXvYqzFmEMiWj97zp1EzLpKg4nY0UI4hec61/Y/qTKrSa1XTVXfcRFkOmKfbGFDe7TI1hRP+/jlTQ== X-Received: by 2002:a17:90a:b396:: with SMTP id e22mr3830679pjr.102.1569380203438; Tue, 24 Sep 2019 19:56:43 -0700 (PDT) Received: from 192-168-1-100.tpgi.com.au (60-241-76-212.tpgi.com.au. [60.241.76.212]) by smtp.gmail.com with ESMTPSA id h15sm3039067pgn.76.2019.09.24.19.56.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Sep 2019 19:56:43 -0700 (PDT) Message-ID: <85cd91320ad71bd44d8d82aed52b29c2b08888ab.camel@gmail.com> Subject: Re: How to get timezone offset in timestamp with time zone AT TIME ZONE output. From: rob stone To: Paul McGarry , Adrian Klaver Cc: Andrew Gierth , pgsql-general@lists.postgresql.org Date: Wed, 25 Sep 2019 12:56:38 +1000 In-Reply-To: References: <87impio1tf.fsf@news-spur.riddles.org.uk> <91469459-36f7-41a4-09e9-c88d693cccef@aklaver.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5-1.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, 2019-09-25 at 10:12 +1000, Paul McGarry wrote: > > On Wed, Sep 25, 2019 at 5:44 AM Adrian Klaver < > adrian.klaver@aklaver.com> wrote: > > > Andrew's function seems plausible and I need to find some time to > test it, but I am slightly surprised there isn't a native way to get > the output, as it seems like something that would be fairly useful > when dealing with dates. > > Perhaps another avenue would be some sort of getOffset function, eg > > getOffset('2019-09-25 02:00:00+00','Australia/Sydney') > that would return +11 (or just 11). > > Presumably PostgreSQL must have some internal functionality like that > because it can do that math on the datetimes, but it doesn't seem to > be exposed to users. > > Thanks all for your input. > > Paul > You can EXTRACT timezone, timezone_hour and timezone_minute from a timestamp. Using 'timezone' returns a value representing seconds from UTC. Maybe you could just concatenate the date/time with the extracted offset in your select statement. HTH, Robert