Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lRWgj-000317-OQ for pgsql-sql@arkaria.postgresql.org; Wed, 31 Mar 2021 08:58:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lRWgi-00085j-FP for pgsql-sql@arkaria.postgresql.org; Wed, 31 Mar 2021 08:58:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lRWgi-00085c-90 for pgsql-sql@lists.postgresql.org; Wed, 31 Mar 2021 08:58:56 +0000 Received: from mail150.strasbourg.4js.com ([77.159.205.150]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lRWge-0008S0-82 for pgsql-sql@lists.postgresql.org; Wed, 31 Mar 2021 08:58:55 +0000 Received: from [192.168.1.34] (lfbn-str-1-71-12.w92-140.abo.wanadoo.fr [92.140.198.12]) (authenticated bits=0) by mail150.strasbourg.4js.com (8.14.4/8.14.4/Debian-4+deb7u1) with ESMTP id 12V8wnju012045 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 31 Mar 2021 10:58:51 +0200 Subject: Re: Serial sequence name when table/column name in uppercase To: pgsql-sql@lists.postgresql.org References: From: Sebastien FLAESCH Organization: Four Js Development Tools Message-ID: Date: Wed, 31 Mar 2021 10:58:49 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Virus-Scanned: clamav-milter 0.99.4 at mail150 X-Virus-Status: Clean X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.2 (mail150.strasbourg.4js.com [10.10.0.1]); Wed, 31 Mar 2021 10:58:51 +0200 (CEST) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/31/21 10:35 AM, Sebastien FLAESCH wrote: > Hello, > > How do I get the sequence name for a serial/bigserial column, of a table > and/or column name is created with uppercase letters? > > test1=> create table "TAB13" ( "PKEY" BIGSERIAL, "NAME" VARCHAR(50) ); > CREATE TABLE > > test1=> select pg_get_serial_sequence(current_schema||'.tab13','pkey'); > ERROR:  relation "public.tab13" does not exist > > test1=> select pg_get_serial_sequence(current_schema||'.TAB13','PKEY'); > ERROR:  relation "public.tab13" does not exist > > test1=> select * from "TAB13"; >  PKEY | NAME > ------+------ > (0 rows) > > > > Seb > Looking at the V13 doc: https://www.postgresql.org/docs/13/functions-info.html The description for pg_get_serial_sequence() says: "The first parameter is a table name with optional schema, and the second parameter is a column name. Because the first parameter potentially contains both schema and table names, it is parsed per usual SQL rules, meaning it is lower-cased by default. The second parameter, being just a column name, is treated literally and so has its case preserved." To me it means that since this function has no option to preserve the char case for the table name, it can't be used when table uses uppercase characters. Is the only alternative then: pg_get_expr(pg_attrdef.adbin,0) on the default value definition for the serial column, to get for ex: nextval('"TAB13_PKEY_seq"'::regclass) and extract the sequence name from that string using regex for ex? Seb