Is there any alternative word delimiter other than underscore (_) for PostgreSQL objects (fields, tables, etc.) which doesn't require me to use quotes ("") to query?
The special delimiter will be used to separate identically named field names based on their source table. I don't want to use schemas or different tables for this. Some dummy example field names would be:
product_line^product_name
product_line^product_description
service_station^station_name
I've tested out hat (^) and pipe (|), and they don't work.
CREATE TABLE "my^test^table" ( "my^test^field" text )
(I used a GUI to build the tables, and I just now notice that you have to quote the names to even create the table/field.)
Here is what I have to do to query it:
SELECT "my^test^field" FROM "my^test^table"
... while I'd like to do:
SELECT my^test^field FROM my^test^table
... which is possible if I've used underscores (_):
SELECT my_test_field FROM my_test_table
Are there any alternative delimiters other than underscore (_) which could work? Preferably a normal ASCII character which isn't alphanumeric.
Edit: My best alternative at the moment is to use double underscore. But, I'd prefer something else.
You could use dollar signs. From the documentation:
SQL identifiers and key words must begin with a letter (a-z, but also letters with diacritical marks and non-Latin letters) or an underscore (_). Subsequent characters in an identifier or key word can be letters, underscores, digits (0-9), or dollar signs ($). Note that dollar signs are not allowed in identifiers according to the letter of the SQL standard, so their use might render applications less portable.
I do not think it is a good idea.
I often use thematic schemas. Gather objects (tables, views, functions etc) belonging to specific submodels in separate schemas, e.g.:
inventory.items
inventory.get_items()
inventory.document_workflows
sale.contractors
sale.local_orders
etc
where inventory
and sale
are schemas.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With