BUG #18989: Output of \sf does not match original source for E quoted strings (unlike \df+ used to)

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: tim(dot)colles(at)ed(dot)ac(dot)uk
Subject: BUG #18989: Output of \sf does not match original source for E quoted strings (unlike \df+ used to)
Date: 2025-07-17 10:15:47
Message-ID: 18989-48eab8ec8ff535fd@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 18989
Logged by: Tim Colles
Email address: tim(dot)colles(at)ed(dot)ac(dot)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?

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2025-07-17 11:30:40 BUG #18990: The results of equivalent queries are inconsistent (one returns 0, another returns -0)
Previous Message Sajith Prabhakar Shetty 2025-07-17 09:58:42 Re: Postgres: Queries are too slow after upgrading to PG17 from PG15