Thread: libpgtcl and array fields return format - PROPOSAL
Hi, In libpgtcl, pg_select an array field is return as the following string: {"red","blue","green"} and it's rather difficult to process them as a normal tcl list. The same thing for pg_exec, pg_result/tupleArray I think it would be better to return the string as: "red" "blue" "green" and tcl users could directly process the array as an ordinary tcl list. As far as I know, arrays are not heavily used by libpgtcl users (thought it's an interesting feature) so changing format would not affect too many applications but will encourage array field usage in future. What do you think? Constantin Teodorescu FLEX Consulting Braila, ROMANIA
> I think it would be better to return the string as: > "red" "blue" "green" > and tcl users could directly process the array as an ordinary tcl list. Do it! - Thomas -- Thomas Lockhart lockhart@alumni.caltech.edu South Pasadena, California
Thomas Lockhart wrote: > > > I think it would be better to return the string as: > > "red" "blue" "green" > > and tcl users could directly process the array as an ordinary tcl list. > > Do it! All right! Just waited for an official approval! :-) -- Constantin Teodorescu FLEX Consulting Braila, ROMANIA
> > > I think it would be better to return the string as: > > > "red" "blue" "green" > > > and tcl users could directly process the array as an ordinary tcl list. Would it be also possible to use simple lists for arrays on *input* as well as output? The implementation would be symmetric and (presumably) easier to use... - Thomas -- Thomas Lockhart lockhart@alumni.caltech.edu South Pasadena, California
Thomas Lockhart wrote: > > > > > I think it would be better to return the string as: > > > > "red" "blue" "green" > > > > and tcl users could directly process the array as an ordinary tcl list. > > Would it be also possible to use simple lists for arrays on *input* as > well as output? The implementation would be symmetric and (presumably) > easier to use... I am note sure that I am understanding the problem. There is no *input* format in Tcl. The only way for adding data to a table is: pg_exec $dbc "insert into ....." and that's the PostgreSQL syntax. There's no "living" snapshots in Tcl as in JDBC 2 (updatable recordsets). For the moment, the current syntax helps PgAccess. It returns exactly the same format as it would be used to INSERT INTO queries so if you would try to define a table with an array field of strings for example you are able to add records and update them directly from PgAccess. >From that point of view, the new array field return format would give me headaches for Pgaccess in order to restore the {"..","..",".."} format used for updating records. Am I missing something about the *input* format? On the other hand, I have discovered in the libpgtcl source that there is a TCL_ARRAYS that if defined, would return array fields format exactly as a tcl list. But it is not defined anywhere. I think that the behaviour of libpgtcl should be consistent so should we define TCL_ARRAYS by default in the next release? -- Constantin Teodorescu FLEX Consulting Braila, ROMANIA
> For the moment, the current syntax helps PgAccess. It returns exactly > the same format as it would be used to INSERT INTO queries so if you > would try to define a table with an array field of strings for example > you are able to add records and update them directly from PgAccess. > From that point of view, the new array field return format would give me > headaches for Pgaccess in order to restore the {"..","..",".."} format > used for updating records. > Am I missing something about the *input* format? No, that is the issue I was bringing up. Perhaps we at least need "convert to/from" functions to help with formatting arrays?? > On the other hand, I have discovered in the libpgtcl source that there > is a TCL_ARRAYS that if defined, would return array fields format > exactly as a tcl list. But it is not defined anywhere. I think that the > behaviour of libpgtcl should be consistent so should we define > TCL_ARRAYS by default in the next release? So this is what you were proposing anyway, right? Or would you have other changes to make too? - Thomas -- Thomas Lockhart lockhart@alumni.caltech.edu South Pasadena, California
> For the moment, the current syntax helps PgAccess. It returns exactly > the same format as it would be used to INSERT INTO queries so if you > would try to define a table with an array field of strings for example > you are able to add records and update them directly from PgAccess. > >From that point of view, the new array field return format would give me > headaches for Pgaccess in order to restore the {"..","..",".."} format > used for updating records. > > Am I missing something about the *input* format? > > On the other hand, I have discovered in the libpgtcl source that there > is a TCL_ARRAYS that if defined, would return array fields format > exactly as a tcl list. But it is not defined anywhere. I think that the > behaviour of libpgtcl should be consistent so should we define > TCL_ARRAYS by default in the next release? That define is from Massimo. Let's enable it. -- Bruce Momjian | http://www.op.net/~candle maillist@candle.pha.pa.us | (610) 853-3000+ If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania19026
Constantin Teodorescu <teo@flex.ro> writes: > In libpgtcl, pg_select an array field is return as the following string: > {"red","blue","green"} > and it's rather difficult to process them as a normal tcl list. > I think it would be better to return the string as: > "red" "blue" "green" > and tcl users could directly process the array as an ordinary tcl list. Only problem is, how do you know when to make the transformation? It's not that easy to tell in libpq/libpgtcl whether a column has array type or not, and I think stripping '{' ... '}' off a plain text value would be a big no-no. As you noticed later, there is some optional TCL_ARRAYS code that purports to do something like this, but I think it's pretty broken. What seems like it would be fairly safe is to introduce separate Tcl functions that convert between Postgres array format and Tcl list format, and leave it to the user to apply these functions to data that he knows is arrays... regards, tom lane
Re: [INTERFACES] libpgtcl and array fields return format - PROPOSAL
From
Constantin Teodorescu
Date:
Tom Lane wrote: > > As you noticed later, there is some optional TCL_ARRAYS code that > purports to do something like this, but I think it's pretty broken. > > What seems like it would be fairly safe is to introduce separate Tcl > functions that convert between Postgres array format and Tcl list > format, and leave it to the user to apply these functions to data that > he knows is arrays... This is a better idea. I have recompiled libpgtcl with TCL_ARRAYS and noticed that you can fool it by sending a string field formatted as an array and he makes the translation into the list. Not good :-( -- Constantin Teodorescu FLEX Consulting Braila, ROMANIA