Postgres 'syntax error at end of input' when using recursive cte - postgresql

I'm using PostgresSQL with pgAdmin 4.
I'm getting a syntax error at end of input and I'm not sure where the issue is. I'm gonna drop the code below.
The efront table is in the database.
Would appreciate any help in understanding the problem :)
with recursive cte as (
select e.result_data_branch_id as branch_id, e.result_data_branch_id as topBranch_id, e.result_data_branch_name as branch_name
from efront e
where result_data_branch_parent_id is null
union all
select e.result_data_branch_id, cte.topBranch_id, cte.branch_name
from efront e join
cte
on e.result_data_branch_parent_id = cte.branch_id
)

Related

Can you use SQL Views in Geoserver to insert a new database record into a PostGis Datastore?

I have tried to make an entry into a PostGIS Store in Geoserver using a SQL View in Geoserver with the following statement:
INSERT INTO marker_shp(gid, id, geom)
VALUES ((SELECT max(gid) FROM marker_shp)+1, (SELECT max(id) FROM marker_shp)+1, ST_GeomFromText('POINT (499724.5561430572 5268410.813606716)', 32633))
I got the following error message:
ERROR: Syntax error at »INTO« Position: 23
However, the same Query works fine if I use the same SQL Statement in pgAdmin.
If someone could help me out here I would be very thankful.
All the best:
Thomas :)
The syntax should be
INSERT INTO marker_shp(gid, id, geom)
SELECT max(gid) , max(id)+1 F, ST_GeomFromText('POINT (499724.5561430572 5268410.813606716)', 32633))
FROM marker_shp

Error using regular expressions in DB2 - wrong syntax?

i tried to run this query in DB2 ( which includes regex ). I am getting the following error. Can someone help?
Here is the query:
SELECT COUNT(*) FROM TABLE WHERE REGEXP_LIKE(TRIM(FIELD), '[^[:digit:]]')
Support for BOOLEAN data type is new in Db2 11.1.1.1 (i.e. the first Mod Pack + Fix pack for Db2 11.1). If you are only on Db2 11.1.0.0, then you will need to explicitly test the result of your regex function.
SELECT COUNT(*) FROM TABLE
WHERE REGEXP_LIKE(TRIM(FIELD), '[^[:digit:]]') = 1;

tgreenplumrow-Join and Filter is not woking

When i try to execute Multiple Queries in tgreenplumRow component.
It is not allowing me Join and Filter queries.
Input Info
Source and target table both in greenplum only
Source table - Pointing the External source called HDFS
Target TABLE - regular table in greenplum database
Like this
SQL Transaction
Begin;
"insert into target_tbl (select S.* from source_tbl s "LEFT JOIN" target_tbl d ON s."PK"=d."PK" where d."PK" is null) ;
UPDATE target_tbl d
SET
"COL" = s."COL"
FROM source_tbl s
WHERE s."PK"=d."PK" and d."COL" != s."COL"
;
END;
Error I Get:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error on tokens, delete these tokens
Actual Data Flow is
tgreenplumconnection
|
tjdbcinput -->tmap -->thdfsoutput -->tgreenplumrow -->tgreenplumcommit
Q1: How to run multiple queries with Join and filter in txxxROW component.
Q2: Is that possible to Handle above Source and target file scenario in tmap ?
Any Help on this would be much appreciated ?
I like to break these queries into separate components. In your case you want to turn off auto commit on the connection.
So after that mapping you have 2 greenplumRows and 1 commit component.
I think this makes the code more easier to understand and debug, because right now you don't know whether insert or update throws an error.
Don't forget to escape the \ and double quotes with a \ character. I think that what is giving you trouble here.
t*row just simply passes the query that you write in to the database.
In tgreeenplumrow component, you have to simply have the queries in between double quotes like
"Begin;
insert into target_tbl (select S.* from source_tbl s LEFT JOIN target_tbl d ON s.PK=d.PK where d.PK is null) ;
UPDATE target_tbl d
SET
COL = s.COL
FROM source_tbl s
WHERE s.PK=d.PK and d.COL != s.COL;
END;"
Hope this would help you out.

SELECT pgr_nodeNetwork query fails

I am working on windows, and have enabled the extension postgis, pgrouting on database. I have postgreSQL 9.4 installed and i am using the data from boundless workshop (http://workshops.boundlessgeo.com/tutorial-routing/).
SELECT pgr_nodeNetwork('edges',0.001,'geom','gid','noded')
when I run this query, it runs about 1minute and after that time it results in FAIL. How can I solve this issue? My pgr_createTopology query has been successfully run.
NOTICE: PROCESSING:
NOTICE: pgr_nodeNetwork('edges',0.001,'geom','gid','noded')
NOTICE: Performing checks, pelase wait .....
NOTICE: Processing, pelase wait .....
ERROR: line_locate_point: 1st arg isnt a line
CONTEXT: SQL statement "create temp table inter_loc on commit drop as ( select * from (
(select l1id, l2id, st_linelocatepoint(line,source) as locus from intergeom)
union
(select l1id, l2id, st_linelocatepoint(line,target) as locus from intergeom)) as foo
where locus<>0 and locus<>1)"
PL/pgSQL function pgr_nodenetwork(text,double precision,text,text,text) line 184 at EXECUTE statement
********** Error **********
ERROR: line_locate_point: 1st arg isnt a line
SQL state: XX000
Context: SQL statement "create temp table inter_loc on commit drop as ( select * from (
(select l1id, l2id, st_linelocatepoint(line,source) as locus from intergeom)
union
(select l1id, l2id, st_linelocatepoint(line,target) as locus from intergeom)) as foo
where locus<>0 and locus<>1)"
PL/pgSQL function pgr_nodenetwork(text,double precision,text,text,text) line 184 at EXECUTE statement
I ran into this issue in my project and I was stuck on it for hours trying to figure out what was causing it AND how to fix it. I will describe my situation and how I fixed it so hopefully, it helps someone else in the future.
I am using ogr2ogr to import a Shapefile into my database and I was using the -nlt PROMOTE_TO_MULTI as one of my arguments during my import; this caused my geometries to be imported as MultiLineStrings.
From the behavior I've observed and what others have mentioned (and more people), the pgr_nodeNetwork() function does not play nicely with MutliLineStrings.
Since MultiLineStrings won't work for routing, I took the SQL from dkastl's answer and ran it on my data to see if I actually needed MultiLineStrings or if I could just work with LineStrings.
SELECT
COUNT(
CASE WHEN ST_NumGeometries(geom) > 1 THEN 1 END
) AS multi,
COUNT(geom) AS total
FROM network_nodes;
After running that, I found that I had zero need for MultiLineStrings so I reimported my Shapefile with ogr2ogr using -nlt LINESTRING instead and then was able to run pgr_nodeNetwork() without problems.

ERROR: missing FROM-clause entry for table "cte" while executing query in CTE

am trying to execute the following on Postgresql
and am getting
ERROR: missing FROM-clause entry for table "cte"
click here to see my original code
Instead of FROM tempstockpos WHERE .... AND tempstockpos.batchid = cte.batchid, you must include cte in the FROM clause, like:
FROM tempstockpos, cte WHERE .... AND tempstockpos.batchid = cte.batchid
or preferably the cleaner and more readable:
FROM tempstockpos INNER JOIN cte ON tempstockpos.batchid = cte.batchid WHERE ....
The cte table will not be seen out of tempstockpos if it is not defined somewhere out of it. You do now show the whole code.