--- shp2pgsql.c.old	Thu Aug  5 15:30:09 2004
+++ shp2pgsql.c	Thu Aug  5 15:32:45 2004
@@ -1167,9 +1167,19 @@
 
 	free(col_names);
 	if(opt != 'a'){
-		printf("\nALTER TABLE ONLY \"%s\" ADD CONSTRAINT \"%s_pkey\" PRIMARY KEY (gid);\n",table,table);
-		if(j > 1){
-			printf("SELECT setval ('\"%s_gid_seq\"', %i, true);\n", table, j-1);
+		if ( schema )
+		{
+			printf("\nALTER TABLE ONLY \"%s\".\"%s\" ADD CONSTRAINT \"%s_pkey\" PRIMARY KEY (gid);\n",schema,table,table);
+			if(j > 1){
+				printf("SELECT setval ('\"%s\".\"%s_gid_seq\"', %i, true);\n", schema, table, j-1);
+		}
+		}
+		else
+		{
+			printf("\nALTER TABLE ONLY \"%s\" ADD CONSTRAINT \"%s_pkey\" PRIMARY KEY (gid);\n",table,table);
+			if(j > 1){
+				printf("SELECT setval ('\"%s_gid_seq\"', %i, true);\n", table, j-1);
+			}
 		}
 	}
 
