2

As most of us know, Postgres and SQL define reserved and non-reserved key words, like and, all etc. I'm looking for naming conventions in case a column name needs (or is best suited) to be called and, all or say key.

https://www.postgresql.org/docs/current/sql-keywords-appendix.html

What I do is to append _f (field) to given name, for example key_f. But this looks pretty ugly. Is there a standardized naming convention for issue like that or at least the most popular one?

6
  • I seem commercial packages simply append _ to names like that, e.g. key_ or date_. I always try to find a better name, e.g. user_account instead of user - key isn't really a good name to begin with I think as it doesn't really describe what kind of "key" that is. Commented Jul 1, 2021 at 6:11
  • Shouldn't it be _c for a column name? Never mind, simply chose another name. a non-reserved one. Commented Jul 1, 2021 at 7:04
  • To make your code more portable, and forward compatible, you can check out en.wikipedia.org/wiki/SQL_reserved_words. Commented Jul 1, 2021 at 7:05
  • I prepend a z (to be pronounced with a German accent: zdate, zkey , zuser...) Commented Jul 1, 2021 at 9:56
  • Use the second best suited name. That is a better approach than changing the 99.9% of column names that do not need to change. Commented Jul 1, 2021 at 10:56

1 Answer 1

2

You are looking at an old and outdated version of the documentation. Try the current one.

I have never heard of anybody adopting a naming convention to avoid collisions with SQL keywords, so you'd have to come up with your own. Typically, people simply avoid reserved key words. The most notorious one in this context is user.

Sign up to request clarification or add additional context in comments.

1 Comment

Well, I haven't heard either so I was curious how others approach this problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.