pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feed[v10] CREATE TEMP FUNCTION/CREATE FUNCTION PG_TEMP.X
7+ messages / 3 participants
[nested] [flat]
* [v10] CREATE TEMP FUNCTION/CREATE FUNCTION PG_TEMP.X
@ 2017-12-21 16:28 Vincenzo Romano <vincenzo.romano@notorand.it>
0 siblings, 1 reply; 7+ messages in thread
From: Vincenzo Romano @ 2017-12-21 16:28 UTC (permalink / raw)
To: pgsql-general
Hi all.
It seems I cannot use a temporary function.
I know there's no "CREATE TEMP FUNCTION".
But while I can do
tmp2=# CREATE FUNCTION pg_temp.x( OUT b BOOL )
language PLPGSQL
AS $L0$
BEGIN
b := TRUE;
END;
$L0$;
SET search_path TO pg_temp,"$user", public;
the following fails:
tmp2=# SELECT * FROM x();
LINE 1: select * from x();
^
HINT: No function matches the given name and argument types. You
might need to add explicit type casts.
tmp2=# \df+ x
List of functions
Schema | Name | Result data type | Argument data types | Type |
Volatility | Parallel | Owner | Security | Access privileges |
Language | Source code | Description
--------+------+------------------+---------------------+------+------------+----------+-------+----------+-------------------+----------+-------------+-------------
(0 rows)
tmp2=# \df+ pg_temp.x
List of functions
Schema | Name | Result data type | Argument data types | Type |
Volatility | Parallel | Owner | Security | Access privileges |
Language | Source code | Description
--------+------+------------------+---------------------+------+------------+----------+-------+----------+-------------------+----------+-------------+-------------
(0 rows)
but this succeeds:
tmp2=# select * from pg_temp.x();
b
---
t
(1 row)
I think I am doing/thinking something wrong.
But what?
TALIA!
--
Vincenzo Romano - NotOrAnd.IT
Information Technologies
--
NON QVIETIS MARIBVS NAVTA PERITVS
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: [v10] CREATE TEMP FUNCTION/CREATE FUNCTION PG_TEMP.X
@ 2017-12-21 16:52 Tom Lane <tgl@sss.pgh.pa.us>
parent: Vincenzo Romano <vincenzo.romano@notorand.it>
0 siblings, 1 reply; 7+ messages in thread
From: Tom Lane @ 2017-12-21 16:52 UTC (permalink / raw)
To: Vincenzo Romano <vincenzo.romano@notorand.it>; +Cc: pgsql-general
Vincenzo Romano <vincenzo.romano@notorand.it> writes:
> It seems I cannot use a temporary function.
You have to schema-qualify the temp function name when calling it, too.
regards, tom lane
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: [v10] CREATE TEMP FUNCTION/CREATE FUNCTION PG_TEMP.X
@ 2017-12-21 16:53 Vincenzo Romano <vincenzo.romano@notorand.it>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 7+ messages in thread
From: Vincenzo Romano @ 2017-12-21 16:53 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general
2017-12-21 17:52 GMT+01:00 Tom Lane <tgl@sss.pgh.pa.us>:
> Vincenzo Romano <vincenzo.romano@notorand.it> writes:
>> It seems I cannot use a temporary function.
>
> You have to schema-qualify the temp function name when calling it, too.
>
> regards, tom lane
Hi.
So search_path is not used with functions?
--
Vincenzo Romano - NotOrAnd.IT
Information Technologies
--
NON QVIETIS MARIBVS NAVTA PERITVS
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: [v10] CREATE TEMP FUNCTION/CREATE FUNCTION PG_TEMP.X
@ 2017-12-21 16:56 Tom Lane <tgl@sss.pgh.pa.us>
parent: Vincenzo Romano <vincenzo.romano@notorand.it>
0 siblings, 1 reply; 7+ messages in thread
From: Tom Lane @ 2017-12-21 16:56 UTC (permalink / raw)
To: Vincenzo Romano <vincenzo.romano@notorand.it>; +Cc: pgsql-general
Vincenzo Romano <vincenzo.romano@notorand.it> writes:
> 2017-12-21 17:52 GMT+01:00 Tom Lane <tgl@sss.pgh.pa.us>:
>> You have to schema-qualify the temp function name when calling it, too.
> So search_path is not used with functions?
pg_temp is explicitly ignored when searching for functions/operators.
Otherwise, installing a trojan horse is just too easy.
regards, tom lane
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: [v10] CREATE TEMP FUNCTION/CREATE FUNCTION PG_TEMP.X
@ 2017-12-21 17:07 Vincenzo Romano <vincenzo.romano@notorand.it>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 7+ messages in thread
From: Vincenzo Romano @ 2017-12-21 17:07 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general
2017-12-21 17:56 GMT+01:00 Tom Lane <tgl@sss.pgh.pa.us>:
> Vincenzo Romano <vincenzo.romano@notorand.it> writes:
>> 2017-12-21 17:52 GMT+01:00 Tom Lane <tgl@sss.pgh.pa.us>:
>>> You have to schema-qualify the temp function name when calling it, too.
>
>> So search_path is not used with functions?
>
> pg_temp is explicitly ignored when searching for functions/operators.
> Otherwise, installing a trojan horse is just too easy.
>
> regards, tom lane
I'm not sure whether this decision actually makes PG more scure.
But, anyway, thanks for the insight: I've just found the
documentations for this.
--
Vincenzo Romano - NotOrAnd.IT
Information Technologies
--
NON QVIETIS MARIBVS NAVTA PERITVS
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: [v10] CREATE TEMP FUNCTION/CREATE FUNCTION PG_TEMP.X
@ 2017-12-21 23:50 Melvin Davidson <melvin6925@gmail.com>
parent: Vincenzo Romano <vincenzo.romano@notorand.it>
0 siblings, 1 reply; 7+ messages in thread
From: Melvin Davidson @ 2017-12-21 23:50 UTC (permalink / raw)
To: Vincenzo Romano <vincenzo.romano@notorand.it>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general
On Thu, Dec 21, 2017 at 12:07 PM, Vincenzo Romano <
vincenzo.romano@notorand.it> wrote:
> 2017-12-21 17:56 GMT+01:00 Tom Lane <tgl@sss.pgh.pa.us>:
> > Vincenzo Romano <vincenzo.romano@notorand.it> writes:
> >> 2017-12-21 17:52 GMT+01:00 Tom Lane <tgl@sss.pgh.pa.us>:
> >>> You have to schema-qualify the temp function name when calling it, too.
> >
> >> So search_path is not used with functions?
> >
> > pg_temp is explicitly ignored when searching for functions/operators.
> > Otherwise, installing a trojan horse is just too easy.
> >
> > regards, tom lane
>
> I'm not sure whether this decision actually makes PG more scure.
> But, anyway, thanks for the insight: I've just found the
> documentations for this.
>
> --
> Vincenzo Romano - NotOrAnd.IT
> Information Technologies
> --
> NON QVIETIS MARIBVS NAVTA PERITVS
>
>
Aside from the simple explanations you have received, I question your
justification for even having a temporary function.
Functions are only entries in the system catalogs and as such, take up just
a tiny amount of physical space. In addition,
if you ever need it again, you will have to expend time recreating it. Why
not just once and keep it?
--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: [v10] CREATE TEMP FUNCTION/CREATE FUNCTION PG_TEMP.X
@ 2017-12-22 07:33 Vincenzo Romano <vincenzo.romano@notorand.it>
parent: Melvin Davidson <melvin6925@gmail.com>
0 siblings, 0 replies; 7+ messages in thread
From: Vincenzo Romano @ 2017-12-22 07:33 UTC (permalink / raw)
To: Melvin Davidson <melvin6925@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general
2017-12-22 0:50 GMT+01:00 Melvin Davidson <melvin6925@gmail.com>:
>
>
>
> On Thu, Dec 21, 2017 at 12:07 PM, Vincenzo Romano <vincenzo.romano@notorand.it> wrote:
>>
>> 2017-12-21 17:56 GMT+01:00 Tom Lane <tgl@sss.pgh.pa.us>:
>> > Vincenzo Romano <vincenzo.romano@notorand.it> writes:
>> >> 2017-12-21 17:52 GMT+01:00 Tom Lane <tgl@sss.pgh.pa.us>:
>> >>> You have to schema-qualify the temp function name when calling it, too.
>> >
>> >> So search_path is not used with functions?
>> >
>> > pg_temp is explicitly ignored when searching for functions/operators.
>> > Otherwise, installing a trojan horse is just too easy.
>> >
>> > regards, tom lane
>>
>> I'm not sure whether this decision actually makes PG more scure.
>> But, anyway, thanks for the insight: I've just found the
>> documentations for this.
>>
>> --
>> Vincenzo Romano - NotOrAnd.IT
>> Information Technologies
>> --
>> NON QVIETIS MARIBVS NAVTA PERITVS
>>
>
> Aside from the simple explanations you have received, I question your justification for even having a temporary function.
> Functions are only entries in the system catalogs and as such, take up just a tiny amount of physical space. In addition,
> if you ever need it again, you will have to expend time recreating it. Why not just once and keep it?
>
Hi.
Thanks for your comment.
The reason for having temporary object, in my current design, is to
have something shadowing something else on a per session basis, thanks
to the search_path variable.
It's not simply a matter or storage room or access speed. Not at all to me.
If you use, for example:
SET search_path to pg_temp,"$user",public;
you can put general stuff in public, per-user data in "$user" and per
session data in pg_temp.
Then the "name resolution" will follow the above priority during lookup.
And, as I put more and more logics in the DB, having temporary
functions gives me a simple, clean and yet powerful design.
As soon as my applications connect, they run SELECT * FROM
f_application_init( 'MYAPPNAME' ).
That function (which is not temporary) will setup the DB-level, the
user-level and the session-level stuff.
Currently it eats about 500 msec to run and it's run only once per session.
So, the answer to your question is: "why not if it can be useful
"
--
Vincenzo Romano - NotOrAnd.IT
Information Technologies
--
NON QVIETIS MARIBVS NAVTA PERITVS
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2017-12-22 07:33 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-12-21 16:28 [v10] CREATE TEMP FUNCTION/CREATE FUNCTION PG_TEMP.X Vincenzo Romano <vincenzo.romano@notorand.it>
2017-12-21 16:52 ` Tom Lane <tgl@sss.pgh.pa.us>
2017-12-21 16:53 ` Vincenzo Romano <vincenzo.romano@notorand.it>
2017-12-21 16:56 ` Tom Lane <tgl@sss.pgh.pa.us>
2017-12-21 17:07 ` Vincenzo Romano <vincenzo.romano@notorand.it>
2017-12-21 23:50 ` Melvin Davidson <melvin6925@gmail.com>
2017-12-22 07:33 ` Vincenzo Romano <vincenzo.romano@notorand.it>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox