Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVd3S-0005K7-CW for pgsql-general@arkaria.postgresql.org; Fri, 15 Nov 2019 14:58:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iVd3R-00043m-5z for pgsql-general@arkaria.postgresql.org; Fri, 15 Nov 2019 14:58:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVd1b-00007z-9G for pgsql-general@lists.postgresql.org; Fri, 15 Nov 2019 14:56:39 +0000 Received: from vm4651.cloud.seeweb.it ([5.144.172.192]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iVd1V-00061r-A7 for pgsql-general@lists.postgresql.org; Fri, 15 Nov 2019 14:56:35 +0000 Received: from caronte.home.webthatworks.it (host84-209-dynamic.9-87-r.retail.telecomitalia.it [87.9.209.84]) by vm4651.cloud.seeweb.it (Postfix) with ESMTPSA id 9E29621401 for ; Fri, 15 Nov 2019 15:56:29 +0100 (CET) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=webthatworks.it; b=KaK9PTwQIQRpuYJ0eGawwlRBQKSXXPopawz2iFqWrGWAjciqUysb5m7urKPBx1obXOKVajpWrjQ/OBEGD/HnDxNVPTDnf1aqDQ8dye0HM4+gxWDjU7BC/EG23uXyNiKAHr3rkkKMCZv4fnAimwtOppfsIJxVRzY0NNvi+oFlNK0=; h=Received:Received:From:Subject:To:Organization:Message-ID:Date:User-Agent:MIME-Version:Content-Type:Content-Language:Content-Transfer-Encoding; Received: from gloom.home.webthatworks.it (gloom.home.webthatworks.it.home.webthatworks.it [10.3.3.11]) by caronte.home.webthatworks.it (Postfix) with ESMTP id D51FE6FE25B8 for ; Fri, 15 Nov 2019 15:56:27 +0100 (CET) Received: from [127.0.0.1] (localhost [127.0.0.1]) by gloom.home.webthatworks.it (Postfix) with ESMTP id BF5CA5E0454 for ; Fri, 15 Nov 2019 15:56:27 +0100 (CET) From: Ivan Sergio Borgonovo Subject: porting horde to Postgresql 12, dropped pg_attrdef To: pgsql-general@lists.postgresql.org Organization: http://www.WebThatWorks.it Message-ID: Date: Fri, 15 Nov 2019 15:56:27 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Horde (webmail and more) is not anymore compatible with postgresql 12 after pg_attrdef was dropped. Since I'm a Horde user and I've always liked PostgreSQL I'm trying to update these queries 1) SELECT attr.attname, CASE WHEN split_part(def.adsrc, '''', 2) ~ '.' THEN substr(split_part(def.adsrc, '''', 2), strpos(split_part(def.adsrc, '''', 2), '.')+1) ELSE split_part(def.adsrc, '''', 2) END AS relname FROM pg_class t JOIN pg_attribute attr ON (t.oid = attrelid) JOIN pg_attrdef def ON (adrelid = attrelid AND adnum = attnum) JOIN pg_constraint cons ON (conrelid = adrelid AND adnum = conkey[1]) WHERE t.oid = '$table'::regclass AND cons.contype = 'p' AND def.adsrc ~* 'nextval'; This result eg in attname | relname ---------+--------------------- id | horde_alarms_id_seq 2) SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = ' . $this->quote($tableName) . '::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum This result eg in attname | format_type | adsrc | attnotnull id | integer | nextval('public.horde_alarms_id_seq'::regclass) | t As for 1) I think I can replicate the first query mixing up: SELECT c.column_name, c.ordinal_position FROM information_schema.key_column_usage AS c LEFT JOIN information_schema.table_constraints AS t ON t.constraint_name = c.constraint_name WHERE t.table_name = '' AND t.constraint_type = 'PRIMARY KEY'; select pg_get_serial_sequence('', '') But it would be nice to avoid something postgres specific to retrieve the sequence name. Is there any alternative to pg_get_serial_sequence()? The 2) query is used to fill a PHP object that seems to be used to "recreate" the query to create the table. I can get most of what I need from information_schema.columns but I was wondering if there is a way to come up with actual "type definition" as format_type() or pg_typeof(). Furthermore querying the information_schema.columns return nextval('horde_alarms_id_seq'::regclass) in spite of nextval('public.horde_alarms_id_seq'::regclass) and I wonder if it is going to make a difference and if there is a way to totally mimic the result of the original query. Thanks -- Ivan Sergio Borgonovo https://www.webthatworks.it https://www.borgonovo.net