Re: Using Insert with case - Mailing list pgsql-general

From David Johnston
Subject Re: Using Insert with case
Date
Msg-id 012901cd74ef$353b7ff0$9fb27fd0$@yahoo.com
Whole thread Raw
In response to Using Insert with case  ("Bob Pawley" <rjpawley@shaw.ca>)
List pgsql-general
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Bob Pawley
Sent: Tuesday, August 07, 2012 6:26 PM
To: Postgresql
Subject: [GENERAL] 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.





pgsql-general by date:

Previous
From: "Bob Pawley"
Date:
Subject: Re: Using Insert with case
Next
From: Haiming Zhang
Date:
Subject: PostgreSQL 9.1 product code