agora inbox for pgsql-docs@postgresql.org  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: jian he <jian.universality@gmail.com>
Cc: pgsql-docs@lists.postgresql.org
Subject: Re: substring synopsis section, third argument is optional doc didn't show that
Date: Tue, 21 Jan 2025 11:53:24 -0500
Message-ID: <3354664.1737478404@sss.pgh.pa.us> (raw)
In-Reply-To: <CACJufxG0npso=EwpMHeqG1tFhHayo9o51cTfjP9imj3WNvVBvA@mail.gmail.com>
References: <CACJufxG0npso=EwpMHeqG1tFhHayo9o51cTfjP9imj3WNvVBvA@mail.gmail.com>

jian he <jian.universality@gmail.com> writes:
> https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-SIMILARTO-REGEXP

> """
> or as a plain three-argument function:
> substring(string, pattern, escape-character)
> """

> but here "escape-character" is optional.

> substring(string, pattern [,escape-character])
> would be more accurate.

No, the text is correct as written.  substring(text, text) is a
completely different function that implements POSIX regular
expressions, not SQL regular expressions.  It's described in
the next section (9.7.3).  For example,

regression=# select substring('foobar', 'o.b');
 substring 
-----------
 oob
(1 row)

regression=# select substring('foobar', 'o.b', '');
 substring 
-----------
 
(1 row)

because '.' is a metacharacter in POSIX but not SQL regexps.

			regards, tom lane





view thread (5+ messages)  latest in thread

Message-ID: <3354664.1737478404@sss.pgh.pa.us>
Permalink:  ../3354664.1737478404@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3354664.1737478404@sss.pgh.pa.us

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jian.universality@gmail.com, pgsql-docs@lists.postgresql.org
  Subject: Re: substring synopsis section, third argument is optional doc didn't show that
  In-Reply-To: <3354664.1737478404@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox