Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

referencing parameter values in sql front matter #1653

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

Closed
c-koster opened this issue Sep 12, 2024 · 0 comments
Closed

referencing parameter values in sql front matter #1653

c-koster opened this issue Sep 12, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@c-koster
Copy link

Hi all - I've been following #245 and #1523 and have just implemented some pages with parameterized routes. I am however having a persistent issue with page loading speed.

Using the example of product sales from the docs, suppose I have a [product].md page which defines a parameterized route to look at sales measures for a particular product id. The product file is loaded in the front matter, and the product parameter is passed into the sql statement:

sql:
    product_sales: ./data/product_sales.csv
SELECT
DATE(sale_date) AS sale_day,
SUM(quantity) AS total_quantity_sold,
SUM(total_amount) AS total_sales_amount
FROM product_sales
WHERE product_id = ${observable.params.product}
GROUP BY DATE(sale_date)
ORDER BY sale_day

However, if the number of products in product_sales.csv is large, it seems like it would be better to split up each product into its own file, and load only that file as a table. I know this is now possible for passing parameters to FileAttachment but what if there were something similar for the sql front matter? e.g.:

sql:
    product_sales: ./data/product_sales_{observable.params.product}.csv

Otherwise, how do you suggest working with SQL in parameterized pages? I'm pretty sure I can do everything I need with data loaders, but it is very nice to work with the sql blocks inside the page, particularly as I've got multiple charts that rely on slightly different slices of the same data.

@c-koster c-koster added the enhancement New feature or request label Sep 12, 2024
@observablehq observablehq locked and limited conversation to collaborators Sep 12, 2024
@mbostock mbostock converted this issue into discussion #1654 Sep 12, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant