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

Prepared statements for PostgreSQL #94

Closed
sm-shaw opened this issue Jan 22, 2020 · 1 comment · Fixed by #95
Closed

Prepared statements for PostgreSQL #94

sm-shaw opened this issue Jan 22, 2020 · 1 comment · Fixed by #95

Comments

@sm-shaw
Copy link
Contributor

sm-shaw commented Jan 22, 2020

PostgreSQL functions supports prepared statements https://www.postgresql.org/docs/9.3/sql-prepare.html with testing showing that doing so provides some small percentage performance gains. Similar functionality such as bind variables is already used for other databases:

For example ostat can be prepared once as:

prepare ostat (INTEGER, INTEGER, INTEGER, INTEGER, VARCHAR) AS select * from ostat(\$1,\$2,\$3,\$4,'\$5') as (ol_i_id NUMERIC, ol_supply_w_id NUMERIC, ol_quantity NUMERIC, ol_amount NUMERIC, ol_delivery_d TIMESTAMP, out_os_c_id INTEGER, out_os_c_last VARCHAR, os_c_first VARCHAR, os_c_middle VARCHAR, os_c_balance NUMERIC, os_o_id INTEGER, os_entdate TIMESTAMP, os_o_carrier_id INTEGER)

and repeatedly executed as:

set result [ pg_exec_prepared $lda ostat {} {} $w_id $d_id $c_id $byname $name ]

instead of being parsed each time as follows:

set result [pg_exec $lda "select * from ostat($w_id,$d_id,$c_id,$byname,'$name') as (ol_i_id NUMERIC, ol_supply_w_id NUMERIC, ol_quantity NUMERIC, ol_amount NUMERIC, ol_delivery_d TIMESTAMP, out_os_c_id INTEGER, out_os_c_last VARCHAR, os_c_first VARCHAR, os_c_middle VARCHAR, os_c_balance NUMERIC, os_o_id INTEGER, os_entdate TIMESTAMP, os_o_carrier_id INTEGER)" ]

At the current time prepared statements only support the select used to call functions and therefore PostgreSQL prepared statements do not support stored procedures as they do not support the call command. This issue also to serve as a placeholder if stored procedures become supported to add the same prepared statement functionality.

prepare slev (INTEGER, INTEGER, INTEGER, INTEGER) AS call slev($1,$2,$3, $4);
     ;
     );
ERROR:  syntax error at or near "call"
LINE 1: prepare slev (INTEGER, INTEGER, INTEGER) AS call slev(
                                                 ^
@sm-shaw
Copy link
Contributor Author

sm-shaw commented Mar 3, 2020

Closed per pull request PostgreSQL prepared statements for functions and tablespace option for schema builds #95

@sm-shaw sm-shaw closed this as completed Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant