pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: fabio.pasqualini@ac-reims.fr
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #8677: char(n) - bad limit with arrays of composite type
Date: Thu, 12 Dec 2013 11:48:51 -0500
Message-ID: <18204.1386866931@sss.pgh.pa.us> (raw)
In-Reply-To: <E1Vqp2g-0008Cc-63@wrigleys.postgresql.org>
References: <E1Vqp2g-0008Cc-63@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (2+ messages)

Message-ID: <18204.1386866931@sss.pgh.pa.us>
Permalink:  ../18204.1386866931@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/18204.1386866931@sss.pgh.pa.us

 · 

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-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, fabio.pasqualini@ac-reims.fr
  Subject: Re: BUG #8677: char(n) - bad limit with arrays of composite type
  In-Reply-To: <18204.1386866931@sss.pgh.pa.us>
  References: <E1Vqp2g-0008Cc-63@wrigleys.postgresql.org> <18204.1386866931@sss.pgh.pa.us>

* 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