Zelid
Zelid

Reputation: 7195

Postgresql use alternative character instead of quote for column and table names

Is it possible to use different character instead of " for PostgreSQL table and column names?

Something like:

select [TableID], [TableColumn] from [TableName]

or

select 'TableID', 'TableColumn' from 'TableName'

instead of:

select "TableID", "TableColumn" from "TableName"

I use C# and each time I need to replace " with "" when I paste SQL into a C# string and than back "" to " when I copy C# string to SQL manager.

I wonder is there is anything to use instead of " to quote the names in PostgreSQL.

CamelCase in PostgreSQL require names to be quoted, in other case the names will be automatically lower cased - what I try to avoid.

And yes, I need a camel case table and column names in PostgreSQL to auto map them to C# property names.

Upvotes: 3

Views: 2104

Answers (2)

Mike Varosky
Mike Varosky

Reputation: 390

You can always try using escape characters.

string sql = "select \"TableID\", \"TableColumn\" from \"TableName\"";

This should give you the ability to both keep the double quotes, and add the sql to a string at the same time.

But honestly, unless it's a column name WITH a space. I almost never use the quotes for anything, and any spaces I may hit, I use underscores. So my sql usually looks like;

string sql = "SELECT table_id, table_column FROM table_name";

Upvotes: 1

user330315
user330315

Reputation:

No, this is not possible.

The only allowed quote character for object names is the double quote (as required by the SQL standard).

Upvotes: 3

Related Questions