This file is indexed.

/usr/share/python3-postgresql/libsys.sql is in python3-postgresql 1.0.2-1+b1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
##
# libsys.sql - SQL to support driver features
##
-- Queries for dealing with the PostgreSQL catalogs for supporting the driver.

[lookup_type::first]
SELECT
 ns.nspname as namespace,
 bt.typname,
 bt.typtype,
 bt.typlen,
 bt.typelem,
 bt.typrelid,
 ae.oid AS ae_typid,
 ae.typreceive::oid != 0 AS ae_hasbin_input,
 ae.typsend::oid != 0 AS ae_hasbin_output
FROM pg_catalog.pg_type bt
 LEFT JOIN pg_type ae
  ON (
   bt.typlen = -1 AND
   bt.typelem != 0 AND
   bt.typelem = ae.oid
  )
 LEFT JOIN pg_catalog.pg_namespace ns
  ON (ns.oid = bt.typnamespace)
WHERE bt.oid = $1

[lookup_composite]
-- Get the type Oid and name of the attributes in `attnum` order.
SELECT
 CAST(atttypid AS oid) AS atttypid,
 CAST(attname AS text) AS attname,
 tt.typtype = 'd'      AS is_domain
FROM
 pg_catalog.pg_type t LEFT JOIN pg_catalog.pg_attribute a
  ON (t.typrelid = a.attrelid)
 LEFT JOIN pg_type tt ON (a.atttypid = tt.oid)
WHERE
 attrelid = $1 AND NOT attisdropped AND attnum > 0
ORDER BY attnum ASC

[lookup_basetype_recursive]
SELECT
  (CASE WHEN tt.typtype = 'd' THEN
       (WITH RECURSIVE typehierarchy(typid, depth) AS (
          SELECT
               t2.typbasetype,
               0
           FROM
               pg_type t2
           WHERE
               t2.oid = tt.oid
          UNION ALL
          SELECT
               t2.typbasetype,
               th.depth + 1
           FROM
               pg_type t2,
               typehierarchy th
           WHERE
               th.typid = t2.oid
               AND t2.typbasetype != 0
       ) SELECT typid FROM typehierarchy ORDER BY depth DESC LIMIT 1)

       ELSE NULL
 END)             AS basetypid
FROM
  pg_catalog.pg_type tt
WHERE
  tt.oid = $1

[lookup_basetype]
SELECT
  tt.typbasetype
FROM
  pg_catalog.pg_type tt
WHERE
  tt.oid = $1

[lookup_procedures]
SELECT
 pg_proc.oid,
 pg_proc.*,
 pg_proc.oid::regproc AS _proid,
 pg_proc.oid::regprocedure as procedure_id,
 COALESCE(string_to_array(trim(replace(textin(oidvectorout(proargtypes)), ',', ' '), '{}'), ' ')::oid[], '{}'::oid[])
  AS proargtypes,
 (pg_type.oid = 'record'::regtype or pg_type.typtype = 'c') AS composite
FROM
 pg_catalog.pg_proc LEFT JOIN pg_catalog.pg_type ON (
  pg_proc.prorettype = pg_type.oid
 )

[lookup_procedure_oid::first]
*[lookup_procedures]
 WHERE pg_proc.oid = $1

[lookup_procedure_rp::first]
*[lookup_procedures]
 WHERE pg_proc.oid = regprocedurein($1)

[lookup_prepared_xacts::first]
SELECT
	COALESCE(ARRAY(
		SELECT
			gid::text
		FROM
			pg_catalog.pg_prepared_xacts
		WHERE
			database = current_database()
			AND (
				owner = $1::text
				OR (
					(SELECT rolsuper FROM pg_roles WHERE rolname = $1::text)
				)
			)
		ORDER BY prepared ASC
	), ('{}'::text[]))

[regtypes::column]
SELECT pg_catalog.regtypein(pg_catalog.textout(($1::text[])[i]))::oid AS typoid
FROM pg_catalog.generate_series(1, array_upper($1::text[], 1)) AS g(i)

[xact_is_prepared::first]
SELECT TRUE FROM pg_catalog.pg_prepared_xacts WHERE gid::text = $1

[get_statement_source::first]
SELECT statement FROM pg_catalog.pg_prepared_statements WHERE name = $1

[setting_get]
SELECT setting FROM pg_catalog.pg_settings WHERE name = $1

[setting_set::first]
SELECT pg_catalog.set_config($1, $2, false)

[setting_len::first]
SELECT count(*) FROM pg_catalog.pg_settings

[setting_item]
SELECT name, setting FROM pg_catalog.pg_settings WHERE name = $1

[setting_mget]
SELECT name, setting FROM pg_catalog.pg_settings WHERE name = ANY ($1)

[setting_keys]
SELECT name FROM pg_catalog.pg_settings ORDER BY name

[setting_values]
SELECT setting FROM pg_catalog.pg_settings ORDER BY name

[setting_items]
SELECT name, setting FROM pg_catalog.pg_settings ORDER BY name

[setting_update]
SELECT
	($1::text[][])[i][1] AS key,
	pg_catalog.set_config(($1::text[][])[i][1], $1[i][2], false) AS value
FROM
	pg_catalog.generate_series(1, array_upper(($1::text[][]), 1)) g(i)

[startup_data:transient:first]
-- 8.2 and greater
SELECT
 pg_catalog.version()::text AS version,
 backend_start::text,
 client_addr::text,
 client_port::int
FROM pg_catalog.pg_stat_activity WHERE procpid = pg_catalog.pg_backend_pid()
UNION ALL SELECT
 pg_catalog.version()::text AS version,
 NULL::text AS backend_start,
 NULL::text AS client_addr,
 NULL::int AS client_port
LIMIT 1;

[startup_data_no_start:transient:first]
-- 8.1 only, but is unused as often the backend's activity row is not
-- immediately present.
SELECT
 pg_catalog.version()::text AS version,
 NULL::text AS backend_start,
 client_addr::text,
 client_port::int
FROM pg_catalog.pg_stat_activity WHERE procpid = pg_catalog.pg_backend_pid();

[startup_data_only_version:transient:first]
-- In 8.0, there's nothing there.
SELECT
 pg_catalog.version()::text AS version,
 NULL::text AS backend_start,
 NULL::text AS client_addr,
 NULL::int AS client_port;

[terminate_backends:transient:column]
-- Terminate all except mine.
SELECT
	procpid, pg_catalog.pg_terminate_backend(procpid)
FROM
	pg_catalog.pg_stat_activity
WHERE
	procpid != pg_catalog.pg_backend_pid()

[cancel_backends:transient:column]
-- Cancel all except mine.
SELECT
	procpid, pg_catalog.pg_cancel_backend(procpid)
FROM
	pg_catalog.pg_stat_activity
WHERE
	procpid != pg_catalog.pg_backend_pid()

[sizeof_db:transient:first]
SELECT pg_catalog.pg_database_size(current_database())::bigint

[sizeof_cluster:transient:first]
SELECT SUM(pg_catalog.pg_database_size(datname))::bigint FROM pg_database

[sizeof_relation::first]
SELECT pg_catalog.pg_relation_size($1::text)::bigint

[pg_reload_conf:transient:]
SELECT pg_reload_conf()

[languages:transient:column]
SELECT lanname FROM pg_catalog.pg_language

[listening_channels:transient:column]
SELECT channel FROM pg_catalog.pg_listening_channels() AS x(channel)

[listening_relations:transient:column]
-- listening_relations: old version of listening_channels.
SELECT relname as channel FROM pg_catalog.pg_listener
WHERE listenerpid = pg_catalog.pg_backend_pid();

[notify::first]
-- 9.0 and greater
SELECT
	COUNT(pg_catalog.pg_notify(($1::text[])[i][1], $1[i][2]) IS NULL)
FROM
	pg_catalog.generate_series(1, array_upper($1, 1)) AS g(i)

[release_advisory_shared]
SELECT
	CASE WHEN ($2::int8[])[i] IS NULL
	THEN
		pg_catalog.pg_advisory_unlock_shared(($1::int4[])[i][1], $1[i][2])
	ELSE
		pg_catalog.pg_advisory_unlock_shared($2[i])
	END AS released
FROM
	pg_catalog.generate_series(1, COALESCE(array_upper($2::int8[], 1), array_upper($1::int4[], 1))) AS g(i)

[acquire_advisory_shared]
SELECT COUNT((
	CASE WHEN ($2::int8[])[i] IS NULL
	THEN
		pg_catalog.pg_advisory_lock_shared(($1::int4[])[i][1], $1[i][2])
	ELSE
		pg_catalog.pg_advisory_lock_shared($2[i])
	END
) IS NULL) AS acquired
FROM
	pg_catalog.generate_series(1, COALESCE(array_upper($2::int8[], 1), array_upper($1::int4[], 1))) AS g(i)

[try_advisory_shared]
SELECT
	CASE WHEN ($2::int8[])[i] IS NULL
	THEN
		pg_catalog.pg_try_advisory_lock_shared(($1::int4[])[i][1], $1[i][2])
	ELSE
		pg_catalog.pg_try_advisory_lock_shared($2[i])
	END AS acquired
FROM
	pg_catalog.generate_series(1, COALESCE(array_upper($2::int8[], 1), array_upper($1::int4[], 1))) AS g(i)

[release_advisory_exclusive]
SELECT
	CASE WHEN ($2::int8[])[i] IS NULL
	THEN
		pg_catalog.pg_advisory_unlock(($1::int4[])[i][1], $1[i][2])
	ELSE
		pg_catalog.pg_advisory_unlock($2[i])
	END AS released
FROM
	pg_catalog.generate_series(1, COALESCE(array_upper($2::int8[], 1), array_upper($1::int4[], 1))) AS g(i)

[acquire_advisory_exclusive]
SELECT COUNT((
	CASE WHEN ($2::int8[])[i] IS NULL
	THEN
		pg_catalog.pg_advisory_lock(($1::int4[])[i][1], $1[i][2])
	ELSE
		pg_catalog.pg_advisory_lock($2[i])
	END
) IS NULL) AS acquired -- Guaranteed to be acquired once complete.
FROM
	pg_catalog.generate_series(1, COALESCE(array_upper($2::int8[], 1), array_upper($1::int4[], 1))) AS g(i)

[try_advisory_exclusive]
SELECT
	CASE WHEN ($2::int8[])[i] IS NULL
	THEN
		pg_catalog.pg_try_advisory_lock(($1::int4[])[i][1], $1[i][2])
	ELSE
		pg_catalog.pg_try_advisory_lock($2[i])
	END AS acquired
FROM
	pg_catalog.generate_series(1, COALESCE(array_upper($2::int8[], 1), array_upper($1::int4[], 1))) AS g(i)