pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedNested Schemata, in a Standard-Compliant Way?
5+ messages / 3 participants
[nested] [flat]
* Nested Schemata, in a Standard-Compliant Way?
@ 2021-09-28 13:24 Raymond Brinzer <ray.brinzer@gmail.com>
0 siblings, 2 replies; 5+ messages in thread
From: Raymond Brinzer @ 2021-09-28 13:24 UTC (permalink / raw)
To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Greetings.
For some people the "what?" and "why?" of this will be immediately
obvious from the title, but I'm going to spend a little time on those
before "whether?" and "how?"
We have schemata. They're namespaces; very convenient for organizing
things. They let you group tables and other entities together, and,
by setting search_path, only see the ones which presently interest
you.
In fact, they're pretty similar to directories in a filesystem...
except that they don't nest. Imagine a filesystem where you could
have directories, but the directories could only contain files, not
other directories. (Like the first Unix on the PDP-7, or DOS before
2.0.)
You could, of course, use your own delimiters. And we do; often along
the lines of: schema.category_subcategory_table. You can't really use
these to establish context, however. The system doesn't recognize
category_subcategory as a "place". So you can't easily deal with a
subset of your tables, and the combination of many tables and long
names tends to be messy.
So, for example, I'd like to be able to say something like this:
SELECT * FROM /projects/contacts/people;
Or:
cd /projects/contacts;
SELECT * FROM people;
We use / for division, so that probably isn't plausible, but it makes
for a familiar example.
I'm wondering whether such a feature could be added, without breaking
either existing code, or compliance with the SQL standard. For
instance, borrowing :: from languages like Ruby and Perl:
SELECT * FROM ::projects::contacts::people; -- Absolute path
cd ::projects; -- Session-specific
SELECT * FROM contacts::people; -- Relative path
I'm not necessarily saying this is the best delimiter, but the colon
isn't valid in unquoted identifiers, so it's probably a choice which
would have minimal impact.
Now, you could do a fair job of this just within the client, but my
thought is that this would be better if actually supported by the
database. For instance, having representation in the system tables.
So, then: can it be done? Should it be done? I can say easily that
my database life would be better for having this, but there do tend to
be those nasty lurking problems which aren't obvious.
--
Ray Brinzer
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Nested Schemata, in a Standard-Compliant Way?
@ 2021-09-28 13:36 Tom Lane <tgl@sss.pgh.pa.us>
parent: Raymond Brinzer <ray.brinzer@gmail.com>
1 sibling, 1 reply; 5+ messages in thread
From: Tom Lane @ 2021-09-28 13:36 UTC (permalink / raw)
To: Raymond Brinzer <ray.brinzer@gmail.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Raymond Brinzer <ray.brinzer@gmail.com> writes:
> So, for example, I'd like to be able to say something like this:
> SELECT * FROM /projects/contacts/people;
I looked into this many years ago. (The reason why pg_namespace is called
that and not pg_schema is exactly that I thought it might someday include
sub-schemas.) I don't think it's possible to do it without huge ambiguity
problems, unless you introduce some separator other than dot, as indeed
you suggest here. But I also don't think that using some other separator
is a good idea. There's not that much free punctuation available (unless
you want to step outside core ASCII, which'd bring its own problems).
Pretty much every character that isn't otherwise nailed down is allowed
as an operator character, meaning that redefining it is very likely to
break somebody's application or extension. We had huge problems even
with taking over the => digraph, never mind single characters.
In the end the functionality-versus-problems ratio is just not going
to be very good.
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Nested Schemata, in a Standard-Compliant Way?
@ 2021-09-28 14:13 rob stone <floriparob@gmail.com>
parent: Raymond Brinzer <ray.brinzer@gmail.com>
1 sibling, 1 reply; 5+ messages in thread
From: rob stone @ 2021-09-28 14:13 UTC (permalink / raw)
To: Raymond Brinzer <ray.brinzer@gmail.com>; pgsql-general@lists.postgresql.org
Hello Ray,
On Tue, 2021-09-28 at 09:24 -0400, Raymond Brinzer wrote:
> Greetings.
>
>
>
> I'm wondering whether such a feature could be added, without breaking
> either existing code, or compliance with the SQL standard. For
> instance, borrowing :: from languages like Ruby and Perl:
>
> SELECT * FROM ::projects::contacts::people; -- Absolute path
> cd ::projects; -- Session-specific
> SELECT * FROM contacts::people; -- Relative path
>
Double colons are used for casting.
E.g., $1::INET or $1::INTEGER where $1 is a string.
What you are after are sub schemas.
set schema projects;
set subschema contacts;
select * from people;
I don't know enough about the catalogue tables to know if a tree
structure for schemas is possible, the amount of work involved or even
if there is a valid use case.
My 2 cents.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Nested Schemata, in a Standard-Compliant Way?
@ 2021-09-28 14:14 Raymond Brinzer <ray.brinzer@gmail.com>
parent: rob stone <floriparob@gmail.com>
0 siblings, 0 replies; 5+ messages in thread
From: Raymond Brinzer @ 2021-09-28 14:14 UTC (permalink / raw)
To: rob stone <floriparob@gmail.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
On Tue, Sep 28, 2021 at 10:13 AM rob stone <floriparob@gmail.com> wrote:
> Double colons are used for casting.
> E.g., $1::INET or $1::INTEGER where $1 is a string.
Quite right; slipped my mind. Thank you.
--
Ray Brinzer
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Nested Schemata, in a Standard-Compliant Way?
@ 2021-09-28 14:18 Raymond Brinzer <ray.brinzer@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 5+ messages in thread
From: Raymond Brinzer @ 2021-09-28 14:18 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
On Tue, Sep 28, 2021 at 9:36 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> I don't think it's possible to do it without huge ambiguity
> problems, unless you introduce some separator other than dot, as indeed
> you suggest here.
Heh... the moment I saw you'd replied, I thought, "Uh oh!"... because
I think of you as "the reality guy" here. And, sure enough, you came
with a bucket of cold water. :-)
I haven't explored the matter thoroughly enough to give up all hope in
finding a solution which offers a decent ratio. In the end, though,
it wouldn't surprise me at all if you were right.
Single characters are too dear. Digraphs, maybe. Trigraphs? I know
it's getting ugly, but it still might be a net reduction in ugliness
for some people, which could be ignored by most.
> (The reason why pg_namespace is called
> that and not pg_schema is exactly that I
> thought it might someday include sub-schemas.)
I'd noticed the name; it's encouraging that at least people think it
*would be* a good idea.
--
Ray Brinzer
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2021-09-28 14:18 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-09-28 13:24 Nested Schemata, in a Standard-Compliant Way? Raymond Brinzer <ray.brinzer@gmail.com>
2021-09-28 13:36 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-09-28 14:18 ` Raymond Brinzer <ray.brinzer@gmail.com>
2021-09-28 14:13 ` rob stone <floriparob@gmail.com>
2021-09-28 14:14 ` Raymond Brinzer <ray.brinzer@gmail.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