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

Olivier Dalang olivier.dalang at gmail.com
Thu Jan 15 11:22:25 PST 2015


Hi,

Thanks for your answers.

Of course, I could do that with relations, but in my specific case I prefer
to keep everything in one table (I have some fairly complex triggers to
keep versions history and restrict some operations and have no need for
separate tables).

But I'll have a look at the link you provided, and I also found this in the
meantime :
https://woostuff.wordpress.com/2011/09/05/qgis-tips-custom-feature-forms-with-python-logic/

It seems that with this, there's no limit ;)

Bests,

Olivier


2015-01-12 8:51 GMT+00:00 Matthias Kuhn <matthias.kuhn at gmx.ch>:

>  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 listQgis-user at lists.osgeo.orghttp://lists.osgeo.org/mailman/listinfo/qgis-user
>
>
>
> _______________________________________________
> 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/20150115/0aecfc4a/attachment.html>


More information about the Qgis-user mailing list