Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1awAu2-0005fD-6U for pgsql-docs@arkaria.postgresql.org; Fri, 29 Apr 2016 16:04:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1awAu1-0005eN-O4 for pgsql-docs@arkaria.postgresql.org; Fri, 29 Apr 2016 16:04:25 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1awAu1-0005eH-Bc for pgsql-docs@postgresql.org; Fri, 29 Apr 2016 16:04:25 +0000 Received: from mail-yw0-x232.google.com ([2607:f8b0:4002:c05::232]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1awAty-0006Js-6O for pgsql-docs@postgresql.org; Fri, 29 Apr 2016 16:04:24 +0000 Received: by mail-yw0-x232.google.com with SMTP id o66so198305865ywc.3 for ; Fri, 29 Apr 2016 09:04:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unicheck-com-br.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=fpWpayHit/wT5Xh2RrNz0JrEMDGR4pkmrEhS+6N1w14=; b=CcZ1D6oXojtRhkmBfHn4NhvUWaarn8AFItWXFtCCmWmclCAtLjH4OaK/fIFQEOycQs px1Ytg81q1+pLlpp9dzVW5W7qY4QfU7zE0DlrgtLoB4f0T3dHRrBiwAvtSURSdlJL7dD PS90lUtTb+0uIONINu8BeTgoETczXu+O5ByBvSzdrmT/WXkqIudG1vmjL2kVqvqWcpSm D0U0xOadc0HCjZTqcfA9nUe5LAoUC5yY3vtlEGTKeug9lOXhcIr+skc3Pl/XUTg+sPQj Rs1thSlYII9sq61iCjdC2vWwwyp3V8vA4DG6vBMI17+CUY4eu06NOqGfGrGgGdvKiB9W GYCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=fpWpayHit/wT5Xh2RrNz0JrEMDGR4pkmrEhS+6N1w14=; b=kVFeo4VpqA65UB0FrCO8poMqWsmDQ6fJq4orzHDbgluqjokSRE8/dgO1D14KW694iO AYk00GwlajRKmtynM1gx1TcN3wEB1q4qRxblfk3ZPg3FOYdjn55hkaOA2AarmsgTuQCy JLZGQUsnLmmkHHTrBQJDx09oH3RF3qhrSKgoW7+YRdUOOi/3Idny8sJUpiRUgqrT7CCx kgPAgtb7+aU3s1wLcMREFXojaIvrVlWyFgqwRbI04PtOFNArgP/xBDTo92tgud+9dVcy M+bN+6/S86UnxCUE43GwXl0oVn/twOgYUE0Qv6dgSrvLQ9A+73MV52Rr4PC44TZ2IO/R dpSw== X-Gm-Message-State: AOPr4FUwzOutT+ZGLpnPUevP4rGACKTsrJycVHMhJt5pLNsqxkSZ4FQj6LoXlotArtOcEc2ActS2rbUPveaQcg== MIME-Version: 1.0 X-Received: by 10.176.0.109 with SMTP id 100mr12087167uai.15.1461945860623; Fri, 29 Apr 2016 09:04:20 -0700 (PDT) Received: by 10.31.149.196 with HTTP; Fri, 29 Apr 2016 09:04:20 -0700 (PDT) X-Originating-IP: [186.222.21.23] In-Reply-To: <20160428110753.2700f00d@nikita_desk> References: <20160428110753.2700f00d@nikita_desk> Date: Fri, 29 Apr 2016 13:04:20 -0300 Message-ID: Subject: Re: Date formatting From: "Andrei M. Eichler" To: Mavka Cc: pgsql-docs@postgresql.org Content-Type: multipart/alternative; boundary=001a113ed110b428280531a1cbaf X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-docs Precedence: bulk Sender: pgsql-docs-owner@postgresql.org --001a113ed110b428280531a1cbaf Content-Type: text/plain; charset=UTF-8 I don't understand exactly what are your problem. In the beginning of your email, you said that you want to convert a text to timestamp, which can be done like this: select 'Tue Sep 24 08:56:18 +0000 2013'::timestamp -- 2013-09-24 08:56:18 What you refer as "meaningless parts" are day of week and timezone offset time, which are Dy and OF options on http://www.postgresql.org/docs/9.5/static/functions-formatting.html#FUNCTIONS-FORMATTING-DATETIME-TABLE About ignoring/skipping characters on the format, there is this explanation in the docs: Ordinary text is allowed in to_char templates and will be output literally. You can put a substring in double quotes to force it to be interpreted as literal text even if it contains pattern key words. For example, in'"Hello Year "YYYY', the YYYY will be replaced by the year data, but the single Y in Year will not be. In to_date, to_number, and to_timestamp, double-quoted strings skip the number of input characters contained in the string, e.g. "XX" skips two input characters. 2016-04-28 15:07 GMT-03:00 Mavka : > To convert a string to date I need to omit meaningless parts. I found > this format working well (Twitter dump format): > > SELECT to_timestamp( > 'Tue Sep 24 08:56:18 +0000 2013', > 'xxx Mon DD HH24:MI:SS xxxxx YYYY' > ) > -- 2013-09-24 08:56:18-07 > > In place of "xxx" I can use any non-reserved symbols, e.g.: > > 'aaa Mon DD HH24:MI:SS bbbbb YYYY' > > Number of symbols can vary in some limits, e.g. 'aa' is still working. > > Is it hack or normal behaviour of parser? I did not find any mention of > wildcards or placeholders in documentation: > > http://www.postgresql.org/docs/9.5/static/functions-formatting.html > > Best regards, > Mavka > > P.S. I use PostgreSQL 9.4. > > > -- > Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-docs > --001a113ed110b428280531a1cbaf Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I don't understand exactly what are your problem.=

In the beginning of your email, you said that you= want to convert a text to timestamp, which can be done like this:

select 'Tue Sep 24 08:56:18 +0000 2013'::timestamp=
-- 2013-09-24 08:56:18

What you ref= er as "meaningless parts" are day of week and timezone offset tim= e, which are Dy and OF options on = http://www.postgresql.org/docs/9.5/static/functions-formatting.html#FUNCTIO= NS-FORMATTING-DATETIME-TABLE

About ignoring/sk= ipping characters on the format, there is this explanation in the docs:

Ordinary text is allowed in to_char templates and will be = output literally. You can put a substring in double quotes to force it to b= e interpreted as literal text even if it contains pattern key words. For ex= ample, in'"Hello Year "YYYY', the YYYY will be replaced b= y the year data, but the single Y in Year will not be. In to_date, to_numbe= r, and to_timestamp, double-quoted strings skip the number of input charact= ers contained in the string, e.g. "XX" skips two input characters= .

2016-04-28= 15:07 GMT-03:00 Mavka <mavka_temp@mail.ru>:
To convert a string to date I need to omit meaningless = parts. I found
this format working well (Twitter dump format):

SELECT to_timestamp(
=C2=A0 'Tue Sep 24 08:56:18 +0000 2013',
=C2=A0 'xxx Mon DD HH24:MI:SS xxxxx YYYY'
)
-- 2013-09-24 08:56:18-07

In place of "xxx" I can use any non-reserved symbols, e.g.:

'aaa Mon DD HH24:MI:SS bbbbb YYYY'

Number of symbols can vary in some limits, e.g. 'aa' is still worki= ng.

Is it hack or normal behaviour of parser? I did not find any mention of
wildcards or placeholders in documentation:

http://www.postgresql.org/docs/9.= 5/static/functions-formatting.html

Best regards,
Mavka

P.S. I use PostgreSQL 9.4.


--
Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs

--001a113ed110b428280531a1cbaf--