Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Adding Meta Data to Results #18

Closed
JensRavens opened this issue Nov 28, 2019 · 7 comments
Closed

Feature Request: Adding Meta Data to Results #18

JensRavens opened this issue Nov 28, 2019 · 7 comments
Labels
enhancement New feature or request

Comments

@JensRavens
Copy link

I really like the work you've been doing on this project, as this seems to be the easiest to use Postgres library for Swift so far that also works beautifully on my iOS app.
Now to my request: I'm currently trying to build a new app that would allow the user to type in SQL queries himself on a custom database (so I don't know the schema upfront). The user can use that feature to generate custom reports, charts, ..., and there needs to be a way of naming things and do some introspection of query results.

I do agree with your FAQ saying that one shouldn't use name based indices to retrieve values, but would it be possible to somehow retrieve the name of a column and it's type?

Think about a query like this (that the user will input into a text field of the running app):

SELECT count(*) AS population, born_at
FROM people
GROUP BY born_at

I would like to display the label population in the graph, effectively giving the user the possibility to steer everything about the graph/report with SQL (also finding out that born_at is a date, and therefore correctly displaying it in the UI).

Any hints or directions on this?

@pitfield
Copy link
Member

This is similar to #12.

This information is available from the server. Currently PostgresClientKit doesn't ask for it, for the reasons outlined in the FAQ. Also, fetching this data requires an extra server request & response.

As an enhancement, PostgresClientKit could allow the caller to indicate they wish this metadata, and only perform the extra request in that case.

@pitfield pitfield added the enhancement New feature or request label Dec 23, 2019
@pitfield
Copy link
Member

Some of this metadata is also available in the information_schema, which could be queried without enhancement to PostgresClientKit. But this would require at least partially parsing the SELECT statement (for example, to extract the table name).

@JensRavens
Copy link
Author

Thank you for the response. Parsing it is quite hard (just thinking of cross table joins, functions and all the fancy stuff a user could potentially do to create a select statement). I changed the app architecture now to require a server side component that does the processing and then publishes the content via graphQL. It's a step back in my opinion as I would have liked to keep the app server free, but it works.

@pitfield
Copy link
Member

pitfield commented Jan 6, 2020

Re-opening because it would be a nice enhancement to implement someday.

@pitfield pitfield reopened this Jan 6, 2020
@niklassaers
Copy link

Thanks for making PostgresClientKit. Really useful. :-) I'd like to throw my +1 in here, at least for column names. I get that this would be an extra request, and if that's a problem then perhaps I could specify wanting to get metadata back in the statement?

pitfield pushed a commit that referenced this issue May 28, 2020
Add retrieveColumnMetadata parameter to Statement.execute(...) to control
whether column metadata is retrieved in executing a statement.

Add columns property to Cursor to access retrieved column metadata.
pitfield added a commit that referenced this issue May 28, 2020
@pitfield
Copy link
Member

Added a new parameter, retrieveColumnMetadata, to Statement.execute(...), defaulting to false. If true, result metadata is retrieved and can be accessed through the new columns property of Cursor. The result metadata includes the name and data type of each column in the results (plus some other stuff).

@pitfield
Copy link
Member

Available in v1.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

3 participants