https://github.com/stefanov-sm/pg_spreadsheetml
Export SQL query results in Excel
https://github.com/stefanov-sm/pg_spreadsheetml
plpgsql postgresql
Last synced: 3 months ago
JSON representation
Export SQL query results in Excel
- Host: GitHub
- URL: https://github.com/stefanov-sm/pg_spreadsheetml
- Owner: stefanov-sm
- License: mit
- Created: 2020-02-06T14:50:22.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-10T20:30:07.000Z (almost 5 years ago)
- Last Synced: 2025-01-08T22:38:00.177Z (5 months ago)
- Topics: plpgsql, postgresql
- Language: PLpgSQL
- Homepage:
- Size: 224 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pg_spreadsheetml
Exports an SQL query result into Microsoft Excel format.
pl/pgsql function returns [SpreadsheetML](https://en.wikipedia.org/wiki/Microsoft_Office_XML_formats) (XML format for storing Microsoft Excel spreadsheets) as **setof text**.The prototype of the function is as follows:
```PGSQL
FUNCTION pg_spreadsheetml(arg_query text, arg_parameters json DEFAULT '{}'::json)
RETURNS SETOF text
LANGUAGE plpgsql SECURITY DEFINER
```
__arg_query__ is parameterised by plain text susbtitution (macro expansion).
Macro parameter placeholders are defined as valid uppercase identifiers with two underscores as prefix and suffix, i.e. `__NUMBER_OF_DAYS__`, `__COST__`, etc. See the [example](https://github.com/stefanov-sm/pg_spreadsheetml/tree/master/example) SQL-only and PHP CLI scripts.Optional __arg_parameters__ is JSON with parameters' names/values, e.g.,
`{"number_of_days":"7 days", "cost":15.00}`.
Parameter names are K&R case-insensitive identifiers.__Hyperlinks:__ Cell values that match this regex pattern `^#(.+)##(.+)$`, i.e. #_value_##_URL_ will be presented as hyperlinks.
__Note:__ pg_spreadsheetml is __injection prone__ and therefore it must be declared as a security definer owned by a limited user.
__Note:__ The example runs against the popular [DVD rental](https://www.postgresqltutorial.com/postgresql-sample-database/) sample database.