Bug #76916 [Opn]: pg_meta_data Does Not Respect PostgreSQL search_path
| From: | klaxian at gmail dot com | Date: | Fri, 21 Sep 2018 16:12:10 +0000 |
| Subject: | Bug #76916 [Opn]: pg_meta_data Does Not Respect PostgreSQL search_path | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217186@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76916&edit=1
ID: 76916
User updated by: klaxian at gmail dot com
Reported by: klaxian at gmail dot com
Summary: pg_meta_data Does Not Respect PostgreSQL search_path
Status: Open
Type: Bug
Package: PostgreSQL related
Operating System: Linux
PHP Version: 7.1.22
Block user comment: N
Private report: N
New Comment:
Currently, the function appears to parse the supplied table name for an explicit schema qualifier;
"public" is assumed if one is not found. A query is constructed where c.relname and
n.nspname match the supplied/assumed table and schema respectively. As I mentioned, this ignores
PostgreSQL's search_path.
I suggest querying for the user-supplied table name casted to a PG regclass object instead. This
improves performance because the table string won't need to be parsed and PostgreSQL will
determine the correct object based on its search_path. This is supported in at least PG 7.3+ from
2002 (and likely older).
WHERE a.attrelid='mytable'::regclass
Previous Comments:
------------------------------------------------------------------------
[2018-09-21 15:44:15] klaxian at gmail dot com
Description:
------------
When querying for data about a PostgreSQL table, pg_meta_data() does not respect PostgreSQL's
search_path setting. When the specified table is not explicitly qualified with a schema, the public
schema is always assumed. This is hard-coded in the pgsql extension.
https://github.com/php/php-src/blob/master/ext/pgsql/pgsql.c#L5530
Test script:
---------------
pg_meta_data($link, 'test'); // always looks for "public.test"
Expected result:
----------------
When a table name is not explicitly qualified with a schema name, the server search_path setting
should be used to determine the correct table.
Actual result:
--------------
When a table name is not explicitly qualified with a schema name, the public schema is always
assumed.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76916&edit=1