From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: tim.colles@ed.ac.uk
Subject: BUG #18989: Output of \sf does not match original source for E quoted strings (unlike \df+ used to)
Date: Thu, 17 Jul 2025 10:15:47 +0000
Message-ID: <18989-48eab8ec8ff535fd@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 18989
Logged by: Tim Colles
Email address: tim.colles@ed.ac.uk
PostgreSQL version: 16.9
Operating system: Ubuntu Jammy
Description:
psql testdb
psql (16.9 (Ubuntu 16.9-1.pgdg22.04+1))
Type "help" for help.
testdb=# create function test() returns text language sql begin atomic
select E'\x12' || 'Hello World' || E'\x12'; end;
CREATE FUNCTION
testdb=# \sf test
CREATE OR REPLACE FUNCTION public.test()
RETURNS text
LANGUAGE sql
BEGIN ATOMIC
SELECT ((''::text || 'Hello World'::text) || ''::text);
END
Hence if the output of \sf is used as the source to make some amendment to
the function the result could easily end up unintentionally different to the
original.
Not sure if this is a bug or expected behaviour, but noting that in v14 the
output of \df+ would have been:
Schema | Name | Result data type | Argument data types | Type | Volatility
| Parallel | Owner | Security | Access privileges | Language |
Source code | Description
--------+------+------------------+---------------------+------+------------+----------+----------+----------+-------------------+----------+------------------------------------------------------------------+-------------
public | test | text | | func | volatile
| unsafe | postgres | invoker | | sql | BEGIN
ATOMIC +|
| | | | |
| | | | | | SELECT
(('\x12'::text || 'Hello World'::text) || '\x12'::text);+|
| | | | |
| | | | | | END
|
i.e. the original source is retained better (although still minus the E
prefix on the literal).
If this is expected behaviour perhaps the documentation
(https://www.postgresql.org/docs/current/app-psql.html) which currently says
under \df+ that "Source code for a specific function can be seen using \sf"
could be altered to say something like "an approximation of the source
code", with a warning about using it to directly amend the function?
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-bugs@postgresql.org
Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, tim.colles@ed.ac.uk
Subject: Re: BUG #18989: Output of \sf does not match original source for E quoted strings (unlike \df+ used to)
In-Reply-To: <18989-48eab8ec8ff535fd@postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox