• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Making a query object with only certain columns?

Guest
Sep 18, 2008 Sep 18, 2008

Copy link to clipboard

Copied

I need to make several identical charts using different queries, each using the same columns, say "name" and "age". I figured I could use a makeChart(query) function for this. The trick is, I need to ensure each query I pass in contains the variables "name" and "age".

Rather than have the app blow up when I dont have the right column names, I figured I could have makeGraph() only accept a custom query object containing "name" and "age" as columns. Then when I run all my queries, I can copy the results into this query object and pass that to the makeChart() function. Is this possible?
TOPICS
Advanced techniques

Views

437

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Sep 18, 2008 Sep 18, 2008
What about passing the column names as a parameter? Then the column names could be dynamic. You could set whatever defaults you want. Name and age if you prefer.

Votes

Translate

Translate
Valorous Hero ,
Sep 18, 2008 Sep 18, 2008

Copy link to clipboard

Copied

What about passing the column names as a parameter? Then the column names could be dynamic. You could set whatever defaults you want. Name and age if you prefer.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 18, 2008 Sep 18, 2008

Copy link to clipboard

Copied

I could approach it that way, but I have about 7 different columns to pass so I'd have to pass in 8 parameters each time (query name + 7 cols).

It'd be awesome if I could just say copy my query into this custom query object. Then all I'd need to worry about is the columns being in the right order during copy.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 18, 2008 Sep 18, 2008

Copy link to clipboard

Copied

> I could approach it that way, but I have about 7 different columns to pass so I'd have
> to pass in 8 parameters each time (query name + 7 cols).

Why? If the chart function only uses two of the columns, you would just need to pass in the query object and the two column names that will be used for charting. Though if for some reason you needed all columns, you could always use the query "columnList" variable.

> It'd be awesome if I could just say copy my query into this custom query object.
> Then all I'd need to worry about is the columns being in the right order during copy.

Yes, but you would still have to tell the object what columns to use for the chart. It seems much simpler to just pass the column names into your function and skip the complication of creating a new object.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 18, 2008 Sep 18, 2008

Copy link to clipboard

Copied

quote:

Originally posted by: Vugof
I could approach it that way, but I have about 7 different columns to pass so I'd have to pass in 8 parameters each time (query name + 7 cols).

It'd be awesome if I could just say copy my query into this custom query object. Then all I'd need to worry about is the columns being in the right order during copy.

If you are passing a query with 7 columns, and your function is only going to use 2, how is supposed to know which two to use? You might want to use query of queries to get a two column query and send that to your function.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 18, 2008 Sep 18, 2008

Copy link to clipboard

Copied

> I could approach it that way, but I have about 7 different columns to pass so
> I'd have to pass in 8 parameters each time (query name + 7 cols).

Well: two. The query, and the list of columns.

I'd approach this by just passing in a query, and stipulating in the hint
for the argument that it must have specific columns. Within the method,
check the correct columns are there, and if not: raise an exception.
Garbage in: garbage out. I think you are overcomplicating things with what
you're suggesting.

Conversely, you could have two arguments:
- a query (required)
- a list of column mappings (optional)

If there's no mappings, then the correct columns must be in place. If
there's the mapping list, use those ones instead. There's - of course -
still no guarantee that the columns in the mapping list will be in the
query, but there's only so much one can do to accommodate the calling code.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 19, 2008 Sep 19, 2008

Copy link to clipboard

Copied

LATEST
Thanks for all the feedback! You guys are probably right, I am trying to overcomplicate things. I will go with the passing of the query + list of columns. Dan's QoQ approach seemed like it would achieve what I originally wanted, but I've read performance is not very stellar using this approach.

And I guess I should have been more clear on the 2 column issue - "name" and "age" columns were just examples, in reality I have 7 columns to pass. The list of columns should work well to get all 7. Thanks!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation