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

How can pongo2 does not escape chars which except TokenSymbols? #336

Open
mengying1995 opened this issue Jul 24, 2023 · 0 comments
Open

Comments

@mengying1995
Copy link

mengying1995 commented Jul 24, 2023

func main() {
	sfsLoader, err := pongo2.NewSandboxedFilesystemLoader(".")
	tplset := pongo2.NewSet("name", sfsLoader)
	tpl, tplErr := tplset.FromFile("create-table.sql.tpl")
	out, outErr := tpl.Execute(pongo2.Context{
		"table_settings": "SETTINGS merge_with_ttl_timeout = 86400, storage_policy = 's3'",
	})
	return out
}

create-table.sql.tpl:

CREATE TABLE IF NOT EXISTS db.table
(
    `name` String,
    `type` String,
    `help` String,
    `labels` Map(String, String) DEFAULT map(),
    `value` Float64,
    `timestamp` Int64
)
ENGINE = MergeTree
PARTITION BY toDate(fromUnixTimestamp64Milli(`timestamp`, 'Asia/Shanghai'))
PRIMARY KEY (`timestamp`, `name`)
ORDER BY (`timestamp`, `name`, `labels`)
-- SETTINGS
{% if (table_settings | default : "") == "" %}
SETTINGS merge_with_ttl_timeout = 86400
{% else %}
{{ table_settings }}
{% endif %}
;

out is:

...Omit
...Omit
-- SETTINGS
SETTINGS merge_with_ttl_timeout = 86400, storage_policy = \u0026#39;s3\u0026#39;
;

Why ' is escaped to \u0026#39; ? How can I avoid this?
Because SQL can not parse \u successfully and can not use ; again and again.

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant