I have this column for creating a geometry from SQL Server:
Shape AS ([geometry]::STGeomFromText(((('POINT('+CONVERT([varchar](20);,Longitude))+' ')+CONVERT([varchar](20),Latitude))+')',(4326))), PRIMARY KEY CLUSTERED
I need to create the column from SQL Server to Postgres:
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
I also changed the STGeomFromText to ST_GeomFromText but I'm getting an error in pgAdmin:
ERROR: syntax error at or near "AS"
LINE 32: Shape AS ([geometry]::STGeomFromText(((('POINT('+CONVERT([...
^
********** Error **********
ERROR: syntax error at or near "AS"
SQL state: 42601
Character: 818
Did I missed something to install for postgis or the syntax needs a complete overhaul for postgres?
That syntax is completely invalid for Postgres (and not valid standard SQL either). It seems you blindly copied that definition from SQL Server
The string concatenation operator is || in SQL, not +.
Square brackets are invalid for identifiers in SQL.
Postgres has no CLUSTERED indexes.
But most importantly: Postgres currently (Postgres 11) has no computed (generated) columns so you can't define a column as a computed on using Shape AS <expression>
They will be available in the upcoming version 12 (to be released in Q4/2019).
Related:
PostgreSQL: creating a generated column
Computed / calculated / virtual / derived columns in PostgreSQL
Related
I am new to snowflake so please bear with me.
I am trying to do a very simple thing - specify a column name by literal but am getting sql compilation error
insert into MYDB.MYSCHEMA.MYTABLE (identifier('MYCOLUMN')) values (10);
SQL compiler points into unexpected parenthesis before MYCOLUMN. Skipping the word identifier and single qotes works fine.
Just got a response from Snowflake support. Currently "identifier" is only supported for select statements. It is not implemented for inserts for identifying columns. It does work for identifying tables n both select and insert.
In some Snowflake databases I can run SELECT GET_DDL('Database', 'MyDatabase'); without problem but in another one, I get the following error message
SQL compilation error: Invalid object type: 'EXTERNAL_TABLE'
There might be an external defined in that database but I would still like to extract the DDL recursively on the database...
Is there any trick I could use?
You could try using DESCRIBE EXTERNAL TABLE which describes the virtual columns on the table.
DESCRIBE EXTERNAL TABLE
5.8 Release Notes - March 15-18, 2021
GET_DDL Function: External Table Support
With this release, the GET_DDL function supports returning a DDL statement that can be used to recreate a specified external table.
Note that currently, the GET_DDL output for a specified database or schema does not include any external tables contained in the schema.
I am facing a problem and I can't find a solution for it. I am using Hibernate envers to audit a table (I am using MS SQL as a database).
I get an error when I try to update the table:
com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '-'. "
Any help ?
Thank you
This issue is caused because the sql server being generated contains the square braces around the table name.
i.e. [YOUR_TABLE]
When envers is engaged, it attempts to put auditing output into the table [YOUR_TABLE]_AUD, hence the error message indicating a syntax error near the _ character (following the right square brace).
Can someone help me construct the SQL that I need to query the Projects_dim table using the Linked Server "idwd"?
To test the connection, I ran a sample query using the linked server name. To access the tables on the linked server, I used a four-part naming syntax:
linked_server_name.catalog_ name.schema_name.table_name.
replacing the values, you get:
idwd.idwd.wimr.PROJECTS_DIM
of should it be the following?
idwd..wimr.PROJECTS_DIM
The database name is "idw" but the grid below shows a blank value under "catalog", which is one source of my confusion, though I believe that the more likely approach is to construct the syntax assuming that the catalog part of the qualified table name should be blank as in the following first example.
select * from idwd..wimr.PROJECTS_DIM
Server: Msg 7314, Level 16, State 1, Line 1
OLE DB provider 'idwd' does not contain table '"wimr"."PROJECTS_DIM"'. The table either does not exist or the current user does not have permissions on that table.
select * from idwd.idwd.wimr.PROJECTS_DIM
Server: Msg 7312, Level 16, State 1, Line 1
Invalid use of schema and/or catalog for OLE DB provider 'MSDAORA'. A four-part name was supplied, but the provider does not expose the necessary interfaces to use a catalog and/or schema.
Can someone suggest what I need to do to query this table?
I am using the MS OLEDB Driver for Oracle.
I thought perhaps there is an issue with case-sensitivity, so I tried this:
select * from IDWD..WIMR.PROJECTS_DIM
Server: Msg 7356, Level 16, State 1, Line 1
OLE DB provider 'MSDAORA' supplied inconsistent metadata for a column. Metadata information was changed at execution time.
and this:
select * from IDWD.IDWD.WIMR.PROJECTS_DIM
Server: Msg 7312, Level 16, State 1, Line 1
Invalid use of schema and/or catalog for OLE DB provider 'MSDAORA'. A four-part name was supplied, but the provider does not expose the necessary interfaces to use a catalog and/or schema.
I tried to create a linked server using each of the two likely drivers:
Microsoft OLEDB Provider for
Oracle
Oracle Provider for OLEDB
..without luck.
Do you think it could be a driver issue?
Sounds like you may be on the right track thinking about this as an issue of case sensitivity. Quoting from the Microsoft support document How to set up and troubleshoot a linked server to an Oracle database in SQL Server regarding errors 7312, 7313, 7314:
If you receive these error messages, a
table may be missing in the Oracle
schema or you may not have permissions
on that table. Verify that the schema
name has been typed by using
uppercase. The alphabetical case of
the table and of the columns should be
as specified in the Oracle system
tables.
On the Oracle side, a table or a
column that is created without double
quotation marks is stored in
uppercase. If the table or the column
is enclosed in double quotation marks,
the table or the column is stored as
is.
I just resolved this issue. Oracle was probably upgraded recently if it did worked before.
To resolve I connected to Oracle and did a "descr TABLENAME;" and check whatever column was in problem. In my case, I had a column type as NUMBER without any scale like in this preview.
I asked a DBA to force a scale for these 3 columns and problem is now solved!
But I did find also there is a workaround this solution. You can also change the TSQL
from
SELECT * FROM idwd..wimr.PROJECTS_DIM
to
SELECT * FROM OPENQUERY(idwd,'select * from wimr.PROJECTS_DIM')
And Microsoft Support report a problem if nullability is not set on a column.
More info about my search on Google.
I am setting up Castle Active Record to access a legacy database on an Microsoft SQL Server. The table in question has a column named function. When I attampt to load a record it gives me this error:
Incorrect syntax near the keyword 'function'
This error comes about because the SQL query nhibernate generates attempts to access the column named function, which happens to be a restricted keyword. The fix is to wrap the column name in square braces ([function]) in the SQL statement. Is it possible to tell nhibernate to do this in its autogenerated SQL?
This will help you:
http://quomon.com/question-How-do-I-handle-database-reserved-words-in-NHibernate-1148.aspx
Example where table is a reserved keyword:
<class name="User" table="[user]" lazy="false">
I think the same applies for column names. Wrap them in square braces.