Re: [GENERAL] Planning error in dynamic string creation in plpgsql

2014-01-08 Thread Keith Fiske
Just wanted to say thanks again for the help to those that responded. For anyone curious, this helped me get a more advanced constraint exclusion feature finished for the partition manager I've been working on http://www.keithf4.com/managing-constraint-exclusion-in-table-partitioning/ -- Keith Fi

Re: [GENERAL] Planning error in dynamic string creation in plpgsql

2014-01-06 Thread Keith Fiske
David, That seems to have fixed it! I was going down a path of grabbing the column's type from pg_attribute and trying to work from there, but was still having some of the same issues. Thanks everyone else that replied as well! -- Keith Fiske Database Administrator OmniTI Computer Consulting, In

Re: [GENERAL] Planning error in dynamic string creation in plpgsql

2014-01-06 Thread Adrian Klaver
On 01/06/2014 07:42 AM, David Johnston wrote: Adrian Klaver-3 wrote In the real function I'm writing, the columns to be used in the string being created are pulled from a configuration table, so their types could be anything. So casting the quote_literal() calls is not really an option here.

Re: [GENERAL] Planning error in dynamic string creation in plpgsql

2014-01-06 Thread David Johnston
Adrian Klaver-3 wrote >> >> >> In the real function I'm writing, the columns to be used in the string >> being created are pulled from a configuration table, so their types >> could be anything. So casting the quote_literal() calls is not really an >> option here. >> >> Any help would be appreciate

Re: [GENERAL] Planning error in dynamic string creation in plpgsql

2014-01-05 Thread Keith Fiske
That is not an option either. This is for a publicly released extension and I'm really not going to go requiring another scripting language be installed, especially an untrusted one. -- Keith Fiske Database Administrator OmniTI Computer Consulting, Inc. http://www.keithf4.com On Sun, Jan 5, 201

Re: [GENERAL] Planning error in dynamic string creation in plpgsql

2014-01-05 Thread Pavel Stehule
2014/1/6 Keith Fiske > That fixed it! In the example and my original as well. Thank you very much! > > And wow that was incredibly misleading where the cast was supposed to go > going by the error given and when it was thrown. That EXECUTE statement > works perfectly fine, seeing as the v_record

Re: [GENERAL] Planning error in dynamic string creation in plpgsql

2014-01-05 Thread Adrian Klaver
On 01/05/2014 08:43 PM, Keith Fiske wrote: I can't remove the quote_literal() because the value could potentially be a string, time, or number. Without the loop, quote_literal() handles the variable being any one of those types without any issues and quotes (or doesn't) as needed. Well I tried

Re: [GENERAL] Planning error in dynamic string creation in plpgsql

2014-01-05 Thread Adrian Klaver
On 01/05/2014 08:34 PM, Keith Fiske wrote: Actually, that doesn't work right. Gives weird results when the column is an integer Example: keith=# select min(col1), max(col1) from partman_test.time_static_table_p2014_01_01; min | max -+- 86 | 100 (1 row) keith=# select min(col1::tex

Re: [GENERAL] Planning error in dynamic string creation in plpgsql

2014-01-05 Thread Keith Fiske
I can't remove the quote_literal() because the value could potentially be a string, time, or number. Without the loop, quote_literal() handles the variable being any one of those types without any issues and quotes (or doesn't) as needed. -- Keith Fiske Database Administrator OmniTI Computer Consu

Re: [GENERAL] Planning error in dynamic string creation in plpgsql

2014-01-05 Thread Adrian Klaver
On 01/05/2014 08:34 PM, Keith Fiske wrote: Actually, that doesn't work right. Gives weird results when the column is an integer Example: keith=# select min(col1), max(col1) from partman_test.time_static_table_p2014_01_01; min | max -+- 86 | 100 (1 row) keith=# select min(col1::tex

Re: [GENERAL] Planning error in dynamic string creation in plpgsql

2014-01-05 Thread Adrian Klaver
On 01/05/2014 08:23 PM, Keith Fiske wrote: That fixed it! In the example and my original as well. Thank you very much! And wow that was incredibly misleading where the cast was supposed to go going by the error given and when it was thrown. That EXECUTE statement works perfectly fine, seeing as

Re: [GENERAL] Planning error in dynamic string creation in plpgsql

2014-01-05 Thread Keith Fiske
Actually, that doesn't work right. Gives weird results when the column is an integer Example: keith=# select min(col1), max(col1) from partman_test.time_static_table_p2014_01_01; min | max -+- 86 | 100 (1 row) keith=# select min(col1::text), max(col1::text) from partman_test.time_stat

Re: [GENERAL] Planning error in dynamic string creation in plpgsql

2014-01-05 Thread Keith Fiske
That fixed it! In the example and my original as well. Thank you very much! And wow that was incredibly misleading where the cast was supposed to go going by the error given and when it was thrown. That EXECUTE statement works perfectly fine, seeing as the v_record variable got its assignment with

Re: [GENERAL] Planning error in dynamic string creation in plpgsql

2014-01-05 Thread Adrian Klaver
On 01/05/2014 06:31 PM, Keith Fiske wrote: Running into an issue trying to dynamically create some SQL statements in a plpgsql function. The function below is as simple an example I can make to reproduce the error. The first loop works without any issues, but the second throws an error. CREATE O

Re: [GENERAL] Planning error in dynamic string creation in plpgsql

2014-01-05 Thread Keith Fiske
Sorry, forgot to include that I've tested this on PostgreSQL versions 9.2.6 and 9.3.2 and same thing happens on both. -- Keith Fiske Database Administrator OmniTI Computer Consulting, Inc. http://www.keithf4.com On Sun, Jan 5, 2014 at 9:31 PM, Keith Fiske wrote: > Running into an issue trying

[GENERAL] Planning error in dynamic string creation in plpgsql

2014-01-05 Thread Keith Fiske
Running into an issue trying to dynamically create some SQL statements in a plpgsql function. The function below is as simple an example I can make to reproduce the error. The first loop works without any issues, but the second throws an error. CREATE OR REPLACE FUNCTION testing_record() RETURNS v