[Qgis-user] Postgres arrays in QGIS and form widget

Matthias Kuhn matthias.kuhn at gmx.ch
Mon Jan 12 00:51:59 PST 2015


Hi Olivier,

There is some support for this in the value relation widget. If you
allow multiple selections, it will make use of the array notation,
storing multiple foreign keys ( { fk1, fk2, fk3 } ).

If you want to get further support for this, you could write your own
form elements which is possible for some time (although I haven't seen
it widely used).
http://blog.vitu.ch/10142013-1847/write-your-own-qgis-form-elements

For your last use-case "same number of items" you should consider to
normalize your database and and have two tables linked with a foreign key.

CREATE TABLE lots(
  id serial,
  common_data text
)

CREATE TABLE person(
  id serial,
 first_names text,
 last_names text,
 age int,
 group integer REFERENCES lots(id)
)

Matthias

On 01/11/2015 03:17 PM, Olivier Dalang wrote:
> Hi !
>
> Postgres' arrays are a great feature. They allow store several values
> in one field :
>
> CREATE TABLE lots(
>     id serial,
>     owners text[]
> );
> INSERT INTO lots(owners) VALUES( ARRAY['john','mike','jenny'] );
>
> But is there a way to edit this cleanly in QGIS with the forms ?
> Natively, the form widget will be a plain text input, and the value
> will display like this
> {"john","mike","jenny"}
> This is more or less usable for text fields, but not really clean,
> since the user needs to escape some characters, and it's not very
> readable. But then it's impossible to use with other widgets
> (checkbox, range, etc.)
>
> I'd love to have a dynamic input where the user could add and remove
> fields, and where QGIS widget types could be used.
>
> Actually, I'd even need a form where I'd have the same number of items
> for several arrays, and where adding/removing an item would work on
> several field at once, to work on a table like this :
> CREATE TABLE lots(
>     id serial,
>     first_names text[],
>     last_names text[],
>     age int[]
> );
>
>
> Is there a way to do it ?
> Maybe with python ?
> Has anyone of you already done this and would agree to share ?
> Any pointer in the right direction would be very welcome !
>
> Thanks a lot in advance,
>
>
> Olivier
>
>
>
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20150112/42288f60/attachment.html>


More information about the Qgis-user mailing list