pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Laurenz Albe <laurenz.albe@cybertec.at>
To: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: Information schema sql_identifier
Date: Wed, 23 Dec 2020 08:06:21 -0800
Message-ID: <a0fe9212-c653-cf64-db79-db34b5917b20@aklaver.com> (raw)
In-Reply-To: <612fdeaf511c9eca2ccfff50e605461213890604.camel@cybertec.at>
References: <653c81a9-bc2b-e7a6-1ece-eab59f007400@aklaver.com>
	<612fdeaf511c9eca2ccfff50e605461213890604.camel@cybertec.at>

On 12/22/20 11:21 PM, Laurenz Albe wrote:
> On Tue, 2020-12-22 at 16:07 -0800, Adrian Klaver wrote:
>> This came up in this SO question:
>>
>> https://stackoverflow.com/questions/65416748/postgres-12-4-gives-function-does-not-exists-error
>>
>> Where the query is:
>>
>> SELECT (TABLE_SCHEMA || '"."' || TABLE_NAME) as table_name,
>>          pg_size_pretty(pg_table_size(table_name)) as table_size,
>>          pg_size_pretty(pg_indexes_size(table_name)) AS indexes_size,
>>          pg_size_pretty(pg_total_relation_size(table_name)) as total_size
>> from information_schema.TABLES nowait
>> where TABLE_SCHEMA='myschema'
>> order by pg_total_relation_size(table_name) desc;
>>
>> And the error is:
>>
>> "ERROR:  function pg_table_size(information_schema.sql_identifier) does not exist
>> LINE 1: ..."."' || TABLE_NAME) as table_name, pg_size_pretty(pg_table_s..."
> 
> I don't see the problem.
> 
> Cast "table_name" and "table_schema" to "text" wherever it occurs.

SELECT pg_table_size(table_name::text)  from information_schema.tables 
where table_schema = 'public';
ERROR:  invalid name syntax

Per Tom's post this does not cover special cases of identifiers. The 
above was run on my test database that has all manner of weird things it.

So:

SELECT table_name  from information_schema.tables where table_schema = 
'public' and table_name ilike 'space%';
  table_name
-------------
  space table


SELECT pg_table_size('space table') ;
ERROR:  invalid name syntax

SELECT pg_table_size(quote_ident('space table')) ;
  pg_table_size
---------------
           8192


> 
> Yours,
> Laurenz Albe
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (7+ messages)

Message-ID: <a0fe9212-c653-cf64-db79-db34b5917b20@aklaver.com>
Permalink:  ../a0fe9212-c653-cf64-db79-db34b5917b20@aklaver.com/
Also on:    postgresql.org/message-id/a0fe9212-c653-cf64-db79-db34b5917b20@aklaver.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, laurenz.albe@cybertec.at
  Subject: Re: Information schema sql_identifier
  In-Reply-To: <a0fe9212-c653-cf64-db79-db34b5917b20@aklaver.com>
  References: <653c81a9-bc2b-e7a6-1ece-eab59f007400@aklaver.com> <612fdeaf511c9eca2ccfff50e605461213890604.camel@cybertec.at> <a0fe9212-c653-cf64-db79-db34b5917b20@aklaver.com>

* 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