Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with a column name contains a colon in PostgreSQL

I downloaded the shape data from OSM. I have imported data from Shapefile into PostgreSQL without any problem but I got an error when I do the select statement.

Select addr:city From location;

Error: syntax error at or near ":"

The problem is because of the column name contains a colon. Could anyone help me with this issue? Should I reject this shapefile in the importing process? Is the shapefile normal?

like image 334
Vorleak Chy Avatar asked Feb 09 '11 03:02

Vorleak Chy


People also ask

What does colon mean in PostgreSQL?

The colon (:) is used to select "slices" from arrays. (See Section 5.12.) In certain SQL dialects (such as Embedded SQL), the colon is used to prefix variable names. The asterisk (*) has a special meaning when used in the SELECT command or with the COUNT aggregate function.

What does :: means in PostgreSQL?

The type 'string' syntax is a generalization of the standard: SQL specifies this syntax only for a few data types, but PostgreSQL allows it for all types. The syntax with :: is historical PostgreSQL usage, as is the function-call syntax.

How do I name columns in PostgreSQL?

First, specify the table, which contains the column you want to rename, after the ALTER TABLE clause. Second, provide the column name after the RENAME COLUMN clause. Third, give the new column name after the TO keyword.

Can column name have space in PostgreSQL?

It is acceptable to use spaces when you are aliasing a column name. However, it is not generally good practice to use spaces when you are aliasing a table name. The alias_name is only valid within the scope of the SQL statement.


1 Answers

If you enclose addr:city with quotes it should work:

SELECT "addr:city" FROM "location";

And if you want to use OpenStreetMap data, you don't have to import shapefiles. Instead, you can import planet.osm (or a regional subset) directly with osm2pgsql.

like image 59
Wouter van Nifterick Avatar answered Sep 19 '22 19:09

Wouter van Nifterick