Argument in pgr_createTopology() function as query - postgresql

I am using pgrouting 2.1.0.
I have spatial and non-spatial data in different table(in different schema). Here I am creating a view which contain geom(filled), id(filled) source(blank) and target(blank).
I have tried pgr_createTopology() function but on view it is running as it requires table. Also tried to write query in pgr_createtopology() but not succeeded. Can any one suggest other option.
I can not merge spatial and non-spatial data.

First of all update your pg_routing version as pgr_createTopology() won't run on view for your version. I have used 2.6.0. Next you have to create editable view of your spatial and non-spatial data. This can be done by applying rules to your view. You might be wanting to update source and target columns by running pgr_createTopology() So create a rule like following for your view. Hope that works.
CREATE OR REPLACE RULE update_vv1 AS
ON UPDATE TO view_schema_name.view_table_name
DO INSTEAD
(
UPDATE schema_non_spatial_table.non_spatial_table_name SET source = new.source, target = new.target
WHERE non_spatail_table_name.id = old.id;
);

Related

Updating the table through tOracleOutput in Talend using an additional SQL query

I have a job where I am getting a flow into tOracleOutput where I am updating the table. Now, I have to update that table using an SQL statement, which I guess we have option in Advanced settings of tOracleOuptut, but I don't know how to use it or you can say that I am not getting the settings properly. I referred to official documentation but could not understand. Can any one explain the fields like Name, SQL expression, Position, Reference Column in a better way?
the SQL query which I am using is:
update set COL1=SOMETHING1
where COL2=SOMETHING2
Now, value for COL1 is coming from the flow but COL2 is some column in the table which is not coming from the flow.
Have a look to tOracleRow for such a case.
Hope this helps.
TRF
Using tOracleOutput is helpful when a ready data source (table or file (...) with same columns as destination) the more elaborate your query is, the more you should do as TRF said (and use tOracleRow), but here's an example to your question:
file contain 3 column,
DB table of destination contains 4 column, where the 4th is the date of update, (the first 3 are identical to the input)
so you add the destination's column's name in Name and put the SQL function for the date (eg: SYSDATE) and where to put it (Position) in reference to a column of your choice (Reference Column)
In my view it helps avoid using tMap for a miserable additional column when you want to Insert, but you want to Update, in which case the component doesn't offer the additional column section, plus I don't think you can add the WHERE clause here
Hope it helps

Case-when or if-then to control table creation in Redshift

I have a handful of data sources that I'd like to apply the same analyses to and eventually load into a larger table database (uniformtable). Different sources contain different columns, and sometimes sources involve crosswalk files that I need to join. I'd like to have one query that converts all sources' data into uniformtable formatting, based on a unique key for each source. Something along the lines of this:
case when source.sourceid = 1 then
create uniformtable as
select column1a as uniforma, column1b as uniformb, sourceid from source
else
when source.sourceid = 2 then
create uniformtable as
select column2a as uniforma, column2b as uniformb, sourceid from source
end;
I've tried using if-then and case-when to accomplish this, but I get syntax errors pointing to the very start of my query. Does Redshift allow you to use if logic for this kind of control?
No, this logic is not permitted.
CASE statements are only valid within a SELECT statement.
You would need to perform this logic external to Amazon Redshift, and then just send the final SQL to create the table.

using UPSERT create edges but in vertex class it shows nothing in Orientdb

UPDATE GeoAgentSummary set out = #45:0, in = #21:0, _2015 = sum(_2015, 10.0f) upsert where out = #45:0 and in = #21:0
I am using the above query to either create an edge (if it is not there) or update an existing edge if it already exists in OrientDB
An edge is created between #45:0 and #21:0.
But in Agent(vertex class having clusters 45, 46, 47 and 48) i.e. in #45:0 it is not showing any outgoing edges.
Agent Class a vertex class
I know that this question is three years old, but for somebody else who will google it further:
You can use “upsert” for edges since version 3.0.1 and it will work properly – but you need to do the following:
Create unique index on edge_class (out, in) and – it's strange – The order is important!
To do this, you need to create in and out properties first, otherwise db can't create index and there will be an exception when you will try to run command “Create index”.
Then, use command CREATE EDGE UPSERT FROM TO .
In this case edge will be created only if it is not exists, and it will create in and out properties for vertex classes.
But it still doesn't work for UPDATE command 'cos, as authors said, “The UPDATE/UPSERT works at document level, so it doesn't create the connections from the vertices. Using it, you will have a broken graph” and it still the same.
The UPDATE command acts like a normal document update without taking care of keeping the edge-vertex "synchronization". To do that you'd have to use the UPDATE EDGE that, however, doesn't support the UPSERT.
There is on open issue on github about that https://github.com/orientechnologies/orientdb/issues/4436
Read also this https://github.com/orientechnologies/orientdb/issues/1114

Can we UPSERT an EDGE in orientdb?

Is it possible to get an example to upsert an edge in orientdb. IF it does not exist is there a way to check if the edge exist, if it does then just update the edge else create a new edge. I am using Orientdb 2.1.13 version.
Thank you
via SQL you can use the basic UPDATE command
update written_by SET out = #9:2, in = #16:43, prop="gianni" UPSERT WHERE out = #9:2 and in = #16:43
http://orientdb.com/docs/last/SQL-Update.html
When you use "update written_by SET out = #9:2, in = #16:43, prop="gianni" UPSERT WHERE out = #9:2 and in = #16:43", it doesn't work properly for edges: it will create edge if it doesn't exist, but it will not create in and out properties in vertex, so, for example, you will not able to query MATCH. It works this way cos “The UPDATE/UPSERT works at document level, so it doesn't create the connections from the vertices. Using it, you will have a broken graph”, as authors said.
But you can use “upsert” for edges since version 3.0.1 and it will work properly – but you need to do the following:
Create unique index on edge_class (out, in) and – it's strange – The order is important!
To do this, you need to create in and out properties first, otherwise db can't create index and there will be an exception when you will try to run command “Create index”.
Then, use command CREATE EDGE UPSERT FROM TO .
In this case edge will be created only if it is not exists, and it will create in and out properties for vertex classes.

Update column by other column values in Scala Slick

Is there anyway to update column based on other column value in Slick2. In sql I would do it like this:
UPDATE table SET columna = columnb WHERE appropriate = true
Yes, but not using the "lifted embedded" (Scala collections style) of Slick.
You can:
Use plain SQL (the sqlu interpolator) to write your SQL to get that effect.
Use client-side update, where you read the rows, and update each row, and send it back to the database (possibly inside a transaction). Which is probably not what you want to do, but is an option.
For the lifted-embedded style, Slick issue 497 is worth tracking, as that's probably closest to the change you need.