From: pgsql-general-owner@xxxxxxxxxxxxxx [mailto:pgsql-general-owner@xxxxxxxxxxxxxx] On Behalf Of Bob Pawley Sent: Tuesday, August 07, 2012 6:26 PM To: Postgresql Subject: Using Insert with case Hi select case when somevariable = 2 then (insert into pipe (line) select bob.edge_data.edge_id from bob.edge_data, bob.node, pipe where st_intersects(st_startpoint(bob.edge_data.geom), bob.node.geom) and bob.node.node_id = 415 and pipe.id = 1) I am attempting to use the above. However, with or without the enclosing brackets I get a syntax error on the word into. Help will be appreciated. Bob ============================================================== Your statement is syntactically wrong. If you provide your version and a better idea of what you are trying to accomplish someone may be able to provide meaningful advice. You should also provide the entire query. I assume you are not due to the missing "END" after your CASE construct. There is also no location for "somevariable" to actual come from. As thought starters you can place the INSERT statement into a function OR you can try using WITH ( INSERT RETURNING ); which one if either is workable depends on more information than you have provided. You can also use plpgsql to encapsulate the procedural logic. You can either write a named function or you can use "DO". David J. -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general