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 1hjWlU-000577-3I for pgsql-general@arkaria.postgresql.org; Fri, 05 Jul 2019 22:33:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hjWlS-0005u4-EG for pgsql-general@arkaria.postgresql.org; Fri, 05 Jul 2019 22:33:10 +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 1hjWlS-0005tc-1A for pgsql-general@lists.postgresql.org; Fri, 05 Jul 2019 22:33:10 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hjWlN-0001ue-Ln for pgsql-general@postgresql.org; Fri, 05 Jul 2019 22:33:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x65MWVOT005125; Fri, 5 Jul 2019 18:32:31 -0400 From: Tom Lane To: Adrian Klaver cc: PegoraroF10 , pgsql-general@postgresql.org Subject: Re: Converting to identity columns with domains on PK columns In-reply-to: <70ed1dae-5697-e7cf-5158-cbf231339c40@aklaver.com> References: <1562269287792-0.post@n3.nabble.com> <9dcaef4ca4f464078c22d4658eabd6baf43f9940.camel@cybertec.at> <1562326734199-0.post@n3.nabble.com> <81ddd3d0-bfb0-f52e-318c-622ab8e9fa9b@aklaver.com> <1562356860333-0.post@n3.nabble.com> <25356.1562357780@sss.pgh.pa.us> <1562359797649-0.post@n3.nabble.com> <70ed1dae-5697-e7cf-5158-cbf231339c40@aklaver.com> Comments: In-reply-to Adrian Klaver message dated "Fri, 05 Jul 2019 13:55:48 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <5123.1562365951.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Fri, 05 Jul 2019 18:32:31 -0400 Message-ID: <5124.1562365951@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Adrian Klaver writes: > On 7/5/19 1:49 PM, PegoraroF10 wrote: >> Sorry, the example I was thinking was this one, which works on Firebird, >> using its way of writing, obviously. >> create function myproc(id integer) returns I32 language sql as 'select $1'; >> >> On postgres ERROR: return type mismatch in function declared to return i32 >> What I mean is that Firebird sees I32 and integer as the same, Postgres >> doesn´t. > Yeah, but if you reverse the casting you did in your first example it works: > create function myproc(id integer) returns I32 language sql as 'select > $1::i32'; > CREATE FUNCTION Yeah. This isn't an inherent property of Postgres, it's just that SQL-language functions aren't defined to provide any implicit casting of their results. The given expression must yield exactly the declared function result type. Most other places in PG are laxer and will automatically perform implicit (and maybe assignment) casts for you. I don't remember offhand whether there are good reasons for SQL functions to be picky about this or it's just a shortage of round tuits. I have a vague feeling that there might be some compatibility issues in there, though. regards, tom lane