I run a postgres database with postgis extention. With imposm3 openstreetmap data is loaded into the scheme import. The tables are called osm_point, osm_linestring and osm_polygon.
Imposm is storing NULL as empty fields.
To query a specific attribute of the table, I usually write
select * from import.osm_point where highway <> ''
But only with the attribute natural this query is not working.
As seen in this picture, the attribute natural contains some filled lines and some empty lines.
When running a query to select only natural without empt field, the following is happen.
ERROR: syntax error at or near "<>"
LINE 1: select * from import.osm_point where natural <> ''
^
SQL state: 42601
Character: 46```
Related
I have created in pipeline parameter and i wanted to pass array of tables to perform multiple copy activity. BUT before that i am testing with only one table as a parameter.
I have created below query in expression (sink side of copy activity).
(Please note i am copying from synapse to synapse (from one schema to another))
#concat('select * from DW_GL.',pipeline().parameters.p_param_input_table,' where updated_on >',activity('Old_Lookup1').output.firstRow.date_value,' and updated_on <=',activity('Old_Lookup1').output.firstRow.date_value_new)
My table is in the schema "DW_GL" so i tried to remove it from above expression and still its not working.
i am getting error:
Failure happened on 'Source' side. ErrorCode=SqlOperationFailed,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=A database operation failed with the following error: 'Parse error at line: 1, column: 75: Incorrect syntax near '03'.',Source=,''Type=System.Data.SqlClient.SqlException,Message=Parse error at line: 1, column: 75: Incorrect syntax near '03'.,Source=.Net SqlClient Data Provider,SqlErrorNumber=103010,Class=16,ErrorCode=-2146232060,State=1,Errors=[{Class=16,Number=103010,State=1,Message=Parse error at line: 1, column: 75: Incorrect syntax near '03'.,},],'
i tried removing empty white spaces from expression .
also tried to use direct parameter without concatenate as '#{pipeline().parameters.p_param_input_table}' still not worked.
I think the error is because this concat statement does not include single quotes (') around the date values. You need to use '' to include them, which translates to ''' to end (or begin) a string with ', and '''' to insert JUST a single ':
#concat('select * from DW_GL.',pipeline().parameters.p_param_input_table,' where updated_on > ''',activity('Old_Lookup1').output.firstRow.date_value,''' and updated_on <= ''',activity('Old_Lookup1').output.firstRow.date_value_new, '''')
Below query can also work :
select * from DW_GL.#{pipeline().parameters.p_param_input_table} where updated_on > '#{activity('Old_Lookup1').output.firstRow.date_value}' and updated_on <=' #{activity('Old_Lookup1').output.firstRow.date_value_new}'
%sql select Name_of_School, Safety_Score from SCHOOLS where \
Safety_Score= (select MAX(Safety_Score) from SCHOOLS)
i am trying to execute this query i got the message.
ibm_db_sa://rbm44299:***#dashdb-txn-sbox-yp-lon02-04.services.eu-gb.bluemix.net:50000/BLUDB
(ibm_db_dbi.ProgrammingError) ibm_db_dbi::ProgrammingError: SQLNumResultCols failed: [IBM][CLI Driver][DB2/LINUXX8664] SQL0206N "SAFETY_SCORE" is not valid in the context where it is used. SQLSTATE=42703 SQLCODE=-206
[SQL: select Name_of_School, Safety_Score from SCHOOLS where Safety_Score= (select MAX(Safety_Score) from SCHOOLS)]
(Background on this error at: http://sqlalche.me/e/f405)
SQL0206N is this error message https://www.ibm.com/support/knowledgecenter/SSEPGG_11.5.0/com.ibm.db2.luw.messages.sql.doc/com.ibm.db2.luw.messages.sql.doc-gentopic1.html#sql0206n
SQL0206N name is not valid in the context where it is used.
This error can occur in the following cases:
For an INSERT or UPDATE statement, the specified column is not a column of the table, or view that was specified as the object of the insert or update.
For a SELECT or DELETE statement, the specified column is not a column of any of the tables or views identified in a FROM clause in the statement.
among other cases.
I.e. Column SAFETY_SCORE does not exist in your table. Maybe the column is "Safety_Score" or "Safety Score" or some other name.
If the column name is not in UPPER CASE in your table, you will need to surround it in double quotes.
I could fix by using the %%sql structure and the double quotes :
%%sql
select MAX("Safety Score") AS MAX_SAFETY_SCORE from Chicago_SCHOOLS;
I am trying to select a particular value in the OSM polygon data using DB Manager in QGIS that is connected to the PostGIS database. When I type
SELECT *
FROM planet_osm_polygon
WHERE landuse is not null
This SQL statement works. It gives me all the rows that has the landuse values.
However, if I replace landuse with natural (which is another column name) it gives me an error message. I used another column name for example, leisure. I get the query result.
I am not sure why I can't use natural column heading name. Any clue to solve this error will be appreciated.
natural is a reserved keyword, so you need to enclose it is double quotes:
SELECT * FROM osm_polygons WHERE "natural" is not null;
PS: the same is true if you have a semicolon in the column name:
SELECT * FROM osm_polygons WHERE "addr:housenumber" is not null;
I have a PostGIS query where I really need to have nested queries inside PostGIS function calls:
UPDATE raw.geocoding
SET the_geom = ST_Centroid(
ST_Collect(
SELECT the_geom
FROM raw.geocoding
WHERE hash = ((E'0101000020090C000081610F9CC5DC3341EE672E6E723B3241')::varchar),
SELECT the_geom
FROM raw.geocoding
WHERE hash = ((E'0101000020090C00002CF887E0C5DC3341C9E5B2DF2A383241')::varchar)
)
)
WHERE hash = ((E'3e638a27c6c38f05026252f4a0b57b2e')::varchar)
Unfortunately, this doesn't work. I get a syntax error at the beginning of the nested query:
ERROR: syntax error at or near "SELECT"
LINE 4: SELECT the_geom
^
********** Error **********
ERROR: syntax error at or near "SELECT"
SQL state: 42601
Character: 86
Looks like I cannot have a nested query as a PostGIS function parameter?
I've perused through the PostGIS documentation and cannot find any clear guidance for dealing with this.
It appears Postgres has a way of doing variables in pgSQL, but it's unclear to me how this would be pulled off in a standard query. This is a query that will be run tens or hundreds of thousands of times from a C# program. That aside, I could do a pgSQL stored procedure if required; just wanted to make sure there wasn't a simpler alternative first.
In case you were wondering, the query looks messy because it's the result of a npgsql-generated parameterized query. I think it's fair to say that npgsql is being extra-cautious with redundant typing and escaping.
I am running PostGIS 2.0.1, Postgres 9.1.5, and npgsql 2.0.12.
It sounds like you want a scalar subquery, an expression written like (SELECT ....) (note enclosing parentheses) that contains a query returning either zero rows (NULL result) or one field from one row.
You were most of the way there, you just needed the parens:
UPDATE raw.geocoding
SET the_geom = ST_Centroid(
ST_Collect(
(SELECT the_geom
FROM raw.geocoding
WHERE hash = ((E'0101000020090C000081610F9CC5DC3341EE672E6E723B3241')::varchar)),
(SELECT the_geom
FROM raw.geocoding
WHERE hash = ((E'0101000020090C00002CF887E0C5DC3341C9E5B2DF2A383241')::varchar))
)
)
WHERE hash = ((E'3e638a27c6c38f05026252f4a0b57b2e')::varchar)
Note that subqueries can be used in other places too - table returning subqueries can appear in FROM, for example. The PostgreSQL manual teaches about all this, and is well worth a cover-to-cover read.
If you're doing a lot of these updates, you may find it more efficient to formulate the UPDATE as a join using the PostgreSQL extension UPDATE ... FROM ... WHERE rather than running lots of individual UPDATEs over and over. I just wanted to raise the possibility. See from-list in UPDATE
I am trying to use PostgreSQL's currval function to return the last inserted row id of a table called Concept. Concept has a serial primary key called cid and there was an automatically generated Sequence called Concept_cid_seq.
I try the following statement and get an error:
SELECT currval("Concept_cid_seq");
ERROR: column "Concept_cid_seq" does not exist
LINE 1: SELECT currval("Concept_cid_seq");
^
********** Error **********
ERROR: column "Concept_cid_seq" does not exist
SQL state: 42703
Character: 16
But when I run the query :
SELECT * from "Concept_cid_seq";
I get a table with one row (as I'd expect) showing columns like last_value, start_value, etc...
What am I missing here? Am I passing the wrong information to currval? Why does it say the 'column does not exist?'
It turns out that this was an issue with capitalization and quotes. Because I wanted to preserve the capitalization of the relation name I needed to use both single and double quotes in order to pass the correct relation name to currval.
I changed the query to SELECT currval('"Concept_cid_seq"'); (note the outer single quotes) and it worked correctly.