pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedColumn name beginning with underscore ("_")?
3+ messages / 3 participants
[nested] [flat]
* Column name beginning with underscore ("_")?
@ 2024-11-04 20:02 Jim Rosenberg <jr@amanue.com>
0 siblings, 2 replies; 3+ messages in thread
From: Jim Rosenberg @ 2024-11-04 20:02 UTC (permalink / raw)
To: pgsql-general
Is it considered bad Postgresql practice to have a column name that begins
with the underscore character ("_")?
I'm not sure where this is documented, but I'm seeing that Postgresql
accepts prepending an underscore to a data type name as a kind of alias for
appending [] to define an array data type. So even though Postgresql
doesn't seem to have this problem, a human reader might confuse a column
name beginning with _ as an array data type reference.
Here is why I want to have some column names beginning with "_". I'm
designing a database to shadow a public agency's data. I need some columns
that reflect *my* shadow copy of the data, (like say download date) that
don't have any semantic import with respect to the original data.
Beginning such columns with "_" is a simple way to keep the column names
uncluttered but indicate to the reader that the column applies to *my
copy* but are not columns in the original data.
Comments?
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Column name beginning with underscore ("_")?
@ 2024-11-04 20:10 Tom Lane <tgl@sss.pgh.pa.us>
parent: Jim Rosenberg <jr@amanue.com>
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 2024-11-04 20:10 UTC (permalink / raw)
To: Jim Rosenberg <jr@amanue.com>; +Cc: pgsql-general
Jim Rosenberg <jr@amanue.com> writes:
> Is it considered bad Postgresql practice to have a column name that begins
> with the underscore character ("_")?
I wouldn't say so.
> I'm not sure where this is documented, but I'm seeing that Postgresql
> accepts prepending an underscore to a data type name as a kind of alias for
> appending [] to define an array data type. So even though Postgresql
> doesn't seem to have this problem, a human reader might confuse a column
> name beginning with _ as an array data type reference.
Yeah, the name of the array type associated with a base type "foo"
is normally "_foo" (with some weird rules if that causes a conflict).
So it's best to avoid naming data types with leading underscores ---
and, because tables have associated composite types, that rule applies
to tables as well. But there's no direct restriction on column names.
If you want to keep things simple and avoid leading underscore across
the board, nobody will say that's wrong either.
> Here is why I want to have some column names beginning with "_". I'm
> designing a database to shadow a public agency's data. I need some columns
> that reflect *my* shadow copy of the data, (like say download date) that
> don't have any semantic import with respect to the original data.
> Beginning such columns with "_" is a simple way to keep the column names
> uncluttered but indicate to the reader that the column applies to *my
> copy* but are not columns in the original data.
Of course, if they decide to name something "_foo", you're going to
need to figure out what to do with that.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Column name beginning with underscore ("_")?
@ 2024-11-04 20:33 Adrian Klaver <adrian.klaver@aklaver.com>
parent: Jim Rosenberg <jr@amanue.com>
1 sibling, 0 replies; 3+ messages in thread
From: Adrian Klaver @ 2024-11-04 20:33 UTC (permalink / raw)
To: Jim Rosenberg <jr@amanue.com>; pgsql-general
On 11/4/24 12:02, Jim Rosenberg wrote:
> Is it considered bad Postgresql practice to have a column name that begins
> with the underscore character ("_")?
>
> I'm not sure where this is documented, but I'm seeing that Postgresql
> accepts prepending an underscore to a data type name as a kind of alias for
> appending [] to define an array data type. So even though Postgresql
> doesn't seem to have this problem, a human reader might confuse a column
> name beginning with _ as an array data type reference.
>
> Here is why I want to have some column names beginning with "_". I'm
> designing a database to shadow a public agency's data. I need some columns
> that reflect *my* shadow copy of the data, (like say download date) that
> don't have any semantic import with respect to the original data.
> Beginning such columns with "_" is a simple way to keep the column names
> uncluttered but indicate to the reader that the column applies to *my
> copy* but are not columns in the original data.
To reduce confusion something like?:
my_* or l(ocal)_*
>
> Comments?
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2024-11-04 20:33 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-11-04 20:02 Column name beginning with underscore ("_")? Jim Rosenberg <jr@amanue.com>
2024-11-04 20:10 ` Tom Lane <tgl@sss.pgh.pa.us>
2024-11-04 20:33 ` Adrian Klaver <adrian.klaver@aklaver.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox