nlog didnt insert database when table name uppercase - postgresql

This works fine;
<targets>
<target name="database" xsi:type="Database"
dbProvider="Npgsql.NpgsqlConnection, Npgsql"
connectionString="User ID=postgres;Password=xxx;Host=192.xx;Port=5432;Database=xxx;">
<!--Pooling=true;-->
<commandText>
insert into systemlogs(...;
</commandText>
But when changed to table name as
"SystemLogs"
(same done in database as well) it throws exception;
"couldnt find table name "systemlogs"
which make sense there isnt but why nlog dont realize updated table name?

In PostgreSQL all quoted identifiers (e.g. table and column names) are case sensitive:
See: Are PostgreSQL column names case-sensitive?
So NLog can't find them is you use quotes and the wrong casing.
So don't use quotes or use the correct casing

If you specified the table name as "SystemLogs" inside double quotes then you will need to use it that way also:
insert into "SystemLogs" ...
In Postgresql quoted identifiers retain the case they are quoted with and need to be referred to the same way. If you create as unquoted name SystemLogs then it will be folded to lower case. See below for more detail:
https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

Related

PostgreSQL: How to insert, select, and update values with underscores

I have a table that has a column, file_name. I added file names that contain underscores using insert. Upon select I see spaces where the underscores should be. Apparently the underscore is used for formatting and needs to be escaped.
What is the proper way to insert values with underscores?
How can I update the values with spaces by replacing all spaces with underscores?
What is the proper way to select a row using where when the value has an underscore, such as where file_name = "some_file.txt"
In other words, how and when does the underscore need to be escaped?
There is no need to escape underscores in string literals in Postgres. See this example. Your case may be caused by a strange behavior of client application. Test your queries in psql.

INSERT with alias name is not working on PostgreSQL

SQL Query on PostgreSQL:
insert into TOKEPOOLAMT (TOKEPOOLAMT.TOKEPOOLAMTID,TOKEPOOLAMT.TOKERULEID)
values (151, 176);
Giving error:
com.edb.util.PSQLException:
ERROR: column "tokepoolamt" of relation "tokepoolamt" does not exist
But:
insert into TOKEPOOLAMT (TOKEPOOLAMTID,TOKERULEID) values (151, 176);
is working fine.
Can anybody explain why alias name with column in insert statement not working?
There are no aliases involved here. Your error is that column names in the column list of an INSERT command cannot be table-qualified. #pozs already provided the fitting quote from the manual in his comment.
I don't think it's an issue of case. I tried with both the cases.
That's missing the point. In Postgres, identifiers are folded to lower case unless double-quoted. If you double-quoted a name at creation time you preserved a case sensitive spelling and need to double-quote for the rest of the object's life - unless it was a legal, lower-case name to begin with, then quoting won't make a difference. Details:
Are PostgreSQL column names case-sensitive?

Creating reference with tables

I have two tables that already have data in them and i would like to create reference via postgressql OR SQL shell. The reference should be like this:
[IMG]http://i.imgur.com/SMUEo4r.png[/IMG]
Can anyone tell me how to do that?
alter table statusi
add constraint fk_darbinieki_statusi
foreign key (id_darbinieks) references darbinieki (id_darbinieks);
Note that I used unquoted identifiers which are case insensitive.
Given your screenshot it might be that you created quoted identifiers using double quotes which are case sensitive. "ID_statusi" is a different name than ID_statusi. So maybe you need to use double quotes when running the above statement. In general, using double quotes for identifiers is not such a good idea. It creates more trouble than it's worth.
More details in the manual:
defining foreign keys:http://www.postgresql.org/docs/current/static/ddl-constraints.html#DDL-CONSTRAINTS-FK
Rules for identifiers: http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
ALTER TABLE: http://www.postgresql.org/docs/current/static/sql-altertable.html

Cannot create a database table named 'user' in PostgreSQL

It seems PostgreSQL does not allow to create a database table named 'user'. But MySQL will allow to create such a table.
Is that because it is a key word? But Hibernate cannot identify any issue (even if we set the PostgreSQLDialect).
user is a reserved word and it's usually not a good idea use reserved words for identifiers (tables, columns).
If you insist on doing that you have to put the table name in double quotes:
create table "user" (...);
But then you always need to use double quotes when referencing the table. Additionally the table name is then case-sensitive. "user" is a different table name than "User".
If you want to save yourself a lot of trouble use a different name. users, user_account, ...
More details on quoted identifiers can be found in the manual: http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
It is possible to specify tablename with JPA with next syntax:
#Table(name="\"user\"")
We had this same issue time ago, and we just changed the table name from user to app_user. Due to the use of Hibernate/JPA. We thought it would be easier this way.
Hope this little fix will help someone else.
You can create a table user in a schema other than public.
The example:
CREATE SCHEMA my_schema;
CREATE TABLE my_schema.user(...);
Trailing underscore
The SQL standard explicitly promises to never use a trailing underscore in any keyword or reserved word.
So, to avoid conflicts with any of the over a thousand keywords and reserved words used by various database engines, I name all my database identifiers with a trailing underscore. (Yes, really, over a thousand keywords reserved — I counted them.)
Change this:
CREATE TABLE user ( … ) ;
… to this:
CREATE TABLE user_ ( … ) ;
I do this as a habit for all database names: schemas, tables, columns, indexes, etc.
As an extra benefit, this practice makes quite clear in documentation, email, and such when referring to a programming language variable named user versus the database column user_. Anything with a trailing underscore is obviously from the database side.

Firebird and Table,field name lowercase

I have converted a database from MySQL to Firebird, all tables name and field name are in lowercase, when I query the database, it gives me an error of table not found, because Firebird automatically converted the name of table in the query in UPPERCASE letters, but my table name in database is lowercase.
To query the database, I'm required to enclose the name of the table or the name of the field in double quotes, for example:
SELECT "field1","field2" FROM "table"
Is there a setting in Firebird to allow to query database with table/field name in lowercase letter without quoting it?
No. BTW, I suggest you to always create DB objects in uppercase (and without double quotes) in Firebird. This simplifies a lot, since you can access them writing in any case (even mixed case).