Snowflake DROP TABLE table_name(...) - snowflake-cloud-data-platform

Why the below syntax does not error out:
CREATE TABLE a1 AS SELECT 1 a;
TRUNCATE TABLE a1(sth);
-- SQL compilation error: syntax error line 1 at position 17 unexpected '('.
DROP TABLE a1(sth);
-- A1 successfully dropped.
-- here I would expect an error
Both TRUNCATE TABLE and DROP TABLE take parameter <name>
Specifies the identifier for the table to drop. If the identifier contains spaces, special characters, or mixed-case characters, the entire string must be enclosed in double quotes. Identifiers enclosed in double quotes are also case-sensitive (e.g. "My Object").
Is there a special behaviour for table_name(...)?

In "drop table", the table name does not accept any parameters so it should not accept any parentheses. Please open a ticket and report this bug to Snowflake.

Related

Incorrect syntax near 'FK_dbo.SalesOrderLineTasks_dbo.Events_Event_ID'

When I try and run
alter table salesorderlinetasks drop constraint
'FK_dbo.SalesOrderLineTasks_dbo.Events_Event_ID'
this command in Sql Server Management Studio, I get an error.
Incorrect syntax near 'FK_dbo.SalesOrderLineTasks_dbo.Events_Event_ID'.
What should I do?
It should contain double quotes instead of single quotes.
Use no quotes:
alter table salesorderlinetasks drop constraint
FK_dbo.SalesOrderLineTasks_dbo.Events_Event_ID
Quotes delimit literal text, but alter requires an entity (which is not a text string but a plain entity name).

Sybase ASE issue dropping unique constraint

When dropping a unique constraint both using Sybase Central or iSQL, the drop statement shown is as follows;
alter table user_database.dbo.table_name drop constraint contraint_name
But execution fails with different errors, like this:
If constraint name is between single quotes, the command returns:
Incorrect syntax near the word 'constraint'
If constraint name is between square braquets, the command returns:
The identifier that starts with '[constraint_name' is too long. Maximum lenght is 28.
If constraint name is written alone, the command returns
Incorrect syntax near '.'
I'm 'sa' user and I've tried issuing commands from both master and user_database. Any suggestions?
Don't use any quotes or brackets, and pls post the full final statement. Also try leaving off the db name (make sure you are in that database).

ORA-00911: invalid character error while truncating table

I have a table that name is _VERSION_HISTORY I got ORA-00911 error while truncating this table. Oracle allow the name start with underscore(_) but throws an error while truncating it. Is it a silly mistake?
Oracle does not allow database object names to start with an underscore:
SQL> create table _T34 (col1 number);
create table _T34 (col1 number)
*
ERROR at line 1:
ORA-00911: invalid character
SQL>
So you must have used double quotes when creating that table:
SQL> create table "_T34" (col1 number);
Table created.
SQL>
Having done that once you must use double quotes whenever you reference that object?
SQL> truncate table "_T34";
Table truncated.
SQL>
So is it "a silly mistake"? Yes, but alas on your part (or whoever decided on using double-quotes to circumvent Oracle's naming conventions). Find out more.
It seems like you have tried to execute SQL statement with a special charter in it. I don't think it is to do with the truncate command. You might just replace the truncate with a simple Select and test this scenario. Note that the special character might appear as white space due to the font you are using.

firebird, insert records using query window

I have the database table AllowedFields with the following columns:
ID int
Name Varchar(50)
FieldRecord Decimal(7,2)
I am trying to insert demo records using the following query:
set term ^ ;
EXECUTE BLOCK AS BEGIN
INSERT INTO AllowedFields(Name, FieldRecord) VALUES ("A", 0.00);
INSERT INTO AllowedFields(Name, FieldRecord) VALUES ("E", 13.00);
END^
But I am getting this error message:
Engine Code : 335544569
Engine Message :
Dynamic SQL Error
SQL error code = -206
Column unknown
A
At line 3, column 37
Obviously firebird sees this A value as a column value?
How would I change this script to insert a record. Thanks.
The SQL standard defines double quotes to denote identifiers (table names, column names, constraint names, ...). So "A" identifies a column named A and not a single character.
String literals have to be enclosed in single quotes in SQL. So you need to use 'A' to denote a string (character) literal.
Putting this together you need:
INSERT INTO AllowedFields(Name, FieldRecord) VALUES ('A', 0.00);
INSERT INTO AllowedFields(Name, FieldRecord) VALUES ('E', 13.00);
You should also be aware that the standard requires quoted names to be case-sensitive, so "A" is a different column than "a").
And Firebird follows the standard.

Hiberante and SQL Server Column name

I have a database that uses "-" in it's columns names.
Example
system-test-id
I mapped the table in Hibernate, but when I try to select all, for example, I get this error:
Invalid column name "system"
Notice that only the first word is taken as column name.
Option show_sql in hibernate shows me this:
select this_.system-test-id as system1_0_0_ (...)
EDIT
I had to add \" in the column name on mapping:
#Id
#Column(name="\"system-test-id\"")
private long systemTestId;
#Column(name="\"system-test-id\"") is the JPA defined way to handle quoted identifiers.
Hibernate has a little more friendly syntax using batck-ticks: #Column(name="system-test-id")
The back-ticks (`) or embedded double-quotes indicate the identifier should be quoted and are replaced with dialect-specific identifier quoting.
Please check the difference between
create table #t
(
[id-Column] int
)
and
create table #t
(
id-Column int
)

Resources