Margie, QGIS needs to "know" that the id is guaranteed unique.
If you (but don't try it :-) ran the SQL: UPDATE smaller_leg_final SET id = 0; then all your id values would be set to 0, so it is not a safe assumption that the values in the id column will always be unique. This can be fixed either by creating a unique index on the column, or by setting it as the table's primary key. In either case, the database will not allw duplicate values, so QGIS can safely use the column as the unique id. Your SQL to create the column as a primary key would be: ALTER TABLE smaller_leg_final ADD COLUMN id serial primary key; The SQL to set it as a primary key, now that you have already created it is: ALTER TABLE smaller_leg_final ADD CONSTRAINT smaller_leg_final_pk PRIMARY KEY(id); The SQL to add the unique index is: CREATE UNIQUE INDEX smaller_leg_final_pk ON smaller_leg_final(id); Otherwise I think you are on the right track. Cheers Brent Wood --- On Sat, 4/6/13, Margie Roswell <[email protected]> wrote: From: Margie Roswell <[email protected]> Subject: [postgis-users] unique id in QGIS/PostGIS To: "PostGIS Users Discussion" <[email protected]> Date: Saturday, April 6, 2013, 9:18 PM I've been googling up a storm, now that I've got a local postgis database with QGIS. But still haven't figured out how to display a newly created table. The query I used to create the table: CREATE TABLE smaller_leg_final AS SELECT ST_Buffer(geom,-500) AS geom, legislative_final.district FROM legislative_final WHERE area > 30; I then discovered that I needed a unique ID, and did the following: ALTER TABLE smaller_leg_final ADD COLUMN id serial not null; This successfully populated the ID field with unique integers. However when I go into QGIS, the Primary Key column offers no options. when I click into it, it just asks me to choose an SRID, which I believe I've already done. The table loads, but nothing displays. I honestly feel a bit like a toddler given ice skates and placed on an icy rink. I'm toddling my way around, falling, getting back up, and then looking up and asking: why did I fall? Once upon a time I was at the true cutting edge of GIS... I purchased MapInfo versions 1.1, and upgraded from there for many years. Moving into QGIS/Posgres/postGIS now, and well on the path to success, but .... not... quite... there. Are there any QGIS users here who can help me to display my new table? Do I need a different postgres statement? Is there a different field name expected? Maybe my query generated invalid shapes... But still, the geom field is displaying in the "Add PostGIS layers "Geometry column", but the Primary key column option doesn't allow me to select my 'id' field. Insight welcome. --http://FarmBillPrimer.orghttp://www.BaltimoreUrbanAg.org (Please send events; This site is hungry.) http://www.ExcellentNutrition.org http://www.packtpub.com/drupal-5-views-recipes/book On Thu, Apr 4, 2013 at 11:21 AM, Lelo - Luiz Rogério De Pieri <[email protected]> wrote: Hi all, I'm having a problem to execute a pgsql2shp command using java. My OS is Ubuntu and it's frequently I use to generate shp files using pgsql2shp, but now I want to do it through java. The follow command works fine on terminal pgsql2shp -f pontos_05600202_teste -h myhost -u myuser -P mypasswd -g coordinates my_database "SELECT * from points where id_uploaded_file = 37995"; Now I'm trying to execute the follow code: ProcessBuilder pb = new ProcessBuilder("pgsql2shp", "-f pontos_05600202_teste", "-h myhost", "-u myuser", "-P mypasswd", "-g coordinates", "my_database", "SELECT coordinates, date from points where id_uploaded_file = 37995"); Process proc; proc = pb.start(); InputStream stdin = proc.getInputStream(); InputStreamReader isr = new InputStreamReader(stdin); BufferedReader br = new BufferedReader(isr); String line = null; System.out.println("<OUTPUT>"); while ((line = br.readLine()) != null) System.out.println(line); System.out.println("</OUTPUT>"); int exitVal = proc.waitFor(); System.out.println("Process exitValue: " + exitVal); And the result is: <OUTPUT> Preparing table for user query... Done. Initializing... coordinates: no such attribute in table __pgsql2shp14493_tmp_table </OUTPUT> Does anybody as any idea about it? Thank you for all Best regards -- Rogério De Pieri (Lelo)SCJP 5 Buscando melhorar a cada dia Áudio, Hardware & Softwarewww.twitter.com/lelopieriblogdolelo.wordpress.com _______________________________________________ postgis-users mailing list [email protected] http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users -----Inline Attachment Follows----- _______________________________________________ postgis-users mailing list [email protected] http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
_______________________________________________ postgis-users mailing list [email protected] http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
