Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vr9Ra-0001LB-LJ for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Dec 2013 16:48:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vr9Ra-0005UH-5B for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Dec 2013 16:48:58 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vr9RZ-0005UA-4I for pgsql-bugs@postgresql.org; Thu, 12 Dec 2013 16:48:57 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vr9RW-0003cF-GT for pgsql-bugs@postgresql.org; Thu, 12 Dec 2013 16:48:56 +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 rBCGmpRg018205; Thu, 12 Dec 2013 11:48:51 -0500 From: Tom Lane To: fabio.pasqualini@ac-reims.fr cc: pgsql-bugs@postgresql.org Subject: Re: BUG #8677: char(n) - bad limit with arrays of composite type In-reply-to: References: Comments: In-reply-to fabio.pasqualini@ac-reims.fr message dated "Wed, 11 Dec 2013 19:01:54 +0000" Date: Thu, 12 Dec 2013 11:48:51 -0500 Message-ID: <18204.1386866931@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org fabio.pasqualini@ac-reims.fr writes: > psql:./enseignement/bts/2014/prog_c++/carnet2/bug/test.sql:25: ERREUR: > valeur trop longue pour le type character(5) > LIGNE 2 : values ( 3,'test3', '{ "(''toto'', ''123'')", "(''titi'', '... > ^ These errors are entirely correct, because you've misunderstood the (admittedly complicated) quoting requirements for nested arrays/records in literal values. Extracting the values that you did manage to store shows the problem: # select (tab_t1)[1].cp from t2; cp ------- '1' '12' (2 rows) The quotes are being taken as data characters, and there's a leading space in there too. The rules for writing composite literals are explained here: http://www.postgresql.org/docs/9.3/static/rowtypes.html#ROWTYPES-IO-SYNTAX On the whole, it's very often easier to use ARRAY[] and ROW() constructors than to get the quoting rules right for literal syntax. I'd have done these examples like this: insert into t2(id_t2, nom, tab_t1) values ( 3,'test3',array[row('toto', '123'), row('titi', '123')]::t1[]); You need an explicit cast unfortunately, because otherwise the ARRAY[] constructor yields record[] which is not considered automatically castable to t1[]. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs