Last active
July 2, 2019 19:47
-
-
Save cans/165ecb5042e8c45b6cd5db18227f1c1f to your computer and use it in GitHub Desktop.
A hastly put together filter plugin for postgres identifier (not yet functional)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A hastly put together filter plugin to try have Ansible's `postgresql_query` module | |
# deal with identifiers correctly. | |
# References: | |
# * Postgres identifiers | |
# https://www.postgresql.org/docs/11/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS | |
# * Psycopg2 handling of identifiers (cf. last example in the section) | |
# http://initd.org/psycopg/docs/usage.html#passing-parameters-to-sql-queries | |
from psycopg2 import sql | |
from ansible.plugins.filter import core | |
def pgidentifier(value): | |
core.mandatory(value) # Useful ? | |
return sql.Identifier(value) | |
class FilterModule(object): | |
def filters(self): | |
return {'pgidentifier': pgidentifier, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment