proteus icon indicating copy to clipboard operation
proteus copied to clipboard

Table-qualified prof tags

Open michaelgmiller opened this issue 6 years ago • 4 comments

I have a table schema like:

CREATE TABLE table2 (
  "id" BIGSERIAL PRIMARY KEY,
  "uuid" VARCHAR(36) UNIQUE NOT NULL,
  "column2" VARCHAR(24) NOT NULL
);

CREATE TABLE table1 (
  "id" BIGSERIAL PRIMARY KEY,
  "uuid" VARCHAR(36) UNIQUE NOT NULL,
  "ref" VARCHAR(36) REFERENCES table2(uuid)
);

I'd like to do a query like SELECT * from table1 JOIN table2 ON table1.ref = table2.uuid, and have table2 referenced as a child struct. The problem is that both tables have id and uuid columns. Can I qualify the prof tags so that table2 has a prof tag of prof:"table2.uuid" for example? I know I can use "AS" clauses for each column, but this becomes a maintenance nightmare for any sizable number of queries.

michaelgmiller avatar Jun 07 '18 01:06 michaelgmiller

Hrm, I had started some work so that you could have nested pprof tags; a pprof tag on a named struct field within a struct would work as a prefix for fields within the inner struct with their own pprof tags. There's still some additional work to do to make this functional.

If you have two different fields in the same struct with different pprof tags with different values, I don't see why Proteus wouldn't work right now. All that matters is that there is a column in the result set whose name matches a pprof tag. If that's not working, let me know (a small example is best), and I can see what's going on.

jonbodner avatar Jun 07 '18 02:06 jonbodner

The issue is that with SELECT *, the columns have clashing names in the result set. So in the above query, the result will have table1.uuid and table2.uuid. I'd like to reference the table qualifiers in a prof tag. Should this work? If not, is there any way around this, without renaming every single column by hand?

michaelgmiller avatar Jun 07 '18 02:06 michaelgmiller

Doing some research, seems that it's not possible to bulk rename columns in the query https://www.postgresql.org/message-id/4CA2A1F3.9000708%40darrenduncan.net - so in the case of joining two tables together with the same columns (for example id or uuid), you have to explicitly enumerate each column with an AS clause, which is kinda painful.

michaelgmiller avatar Jun 07 '18 21:06 michaelgmiller

Let me set up a postgres db and think about what can be done. Unless there are different names, proteus can't assign the values, but maybe there's a different name I can latch on to, or maybe there's a way to specify order information in the columns (which is not my favorite way to access values from a result set)

jonbodner avatar Jun 08 '18 03:06 jonbodner