pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedSyntax question
18+ messages / 12 participants
[nested] [flat]
* Syntax question
@ 2004-07-06 22:42 Tony Li <tony.li@tony.li>
0 siblings, 1 reply; 18+ messages in thread
From: Tony Li @ 2004-07-06 22:42 UTC (permalink / raw)
To: pgsql-general
Hi,
I'm trying to write an application to allow a user to edit an arbitrary
table.
How can I determine the type of a particular field and figure out
whether or
not I should be quoting the value?
I found PQftype() and have reviewed pg_type and pg_attribute, but don't
see
a clean way of figuring this out.
Thanks,
Tony
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: Syntax question
@ 2004-07-07 01:15 David Helgason <david@uti.is>
parent: Tony Li <tony.li@tony.li>
0 siblings, 0 replies; 18+ messages in thread
From: David Helgason @ 2004-07-07 01:15 UTC (permalink / raw)
To: Tony Li <tony.li@tony.li>; +Cc: pgsql-general
(forgot to reply on-list the first time around)
On 7. jul 2004, at 02:28, Tony Li wrote:
> On Jul 6, 2004, at 4:51 PM, David Helgason wrote:
>> On 7. jul 2004, at 00:42, Tony Li wrote:
>>> I'm trying to write an application to allow a user to edit an
>>> arbitrary table.
>>> How can I determine the type of a particular field and figure out
>>> whether or
>>> not I should be quoting the value?
>>
>> You can always quote a value (or just usually?) in PostgreSQL, even
>> numbers, so it shouldn't be a problem. The database will throw an
>> error if the value you sent in can't be coerced into the right type,
>> and that error you can forward to your user. I.e.
>>
>> create table delme (foo integer, bar text);
>> insert into delme (foo, bar) values ('11', 'fru');
>>
> Thanks, but one of my "requirements" is that the user never has to
> type quotes, so
> I have to figure this out.
I see, but if your app just always adds quotes, you'll be allright. See
my example above.
> Tony
David Helgason,
Over the Edge Entertainment
(makers of the Unity 3d-engine http://otee.dk)
^ permalink raw reply [nested|flat] 18+ messages in thread
* Syntax question
@ 2006-05-26 16:09 John Taylor <d_low22003@yahoo.com>
0 siblings, 3 replies; 18+ messages in thread
From: John Taylor @ 2006-05-26 16:09 UTC (permalink / raw)
To: pgsql-general
I have a select statement that goes as follows:
SELECT * FROM product prod, prod_alias pa, category cat, company co
WHERE prod.catid = cat.catid
AND prod.coid = co.coid
AND prod.prodid = pa.prodid;
If possible, I want to change the statement so that I get output regardless of whether there's a match between prod.prodid and pa.prodid. IOW, if there's a match between prod.prodid and pa.prodid, I want the output from both the product table and the prod_alias table. if there's no match, I still want the output from product table. Can I do this in one select statement?
Thanks,
Don
---------------------------------
Ring'em or ping'em. Make PC-to-phone calls as low as 1¢/min with Yahoo! Messenger with Voice.
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: Syntax question
@ 2006-05-26 16:35 Bruno Wolff III <bruno@wolff.to>
parent: John Taylor <d_low22003@yahoo.com>
2 siblings, 0 replies; 18+ messages in thread
From: Bruno Wolff III @ 2006-05-26 16:35 UTC (permalink / raw)
To: John Taylor <d_low22003@yahoo.com>; +Cc: pgsql-general
On Fri, May 26, 2006 at 09:09:25 -0700,
John Taylor <d_low22003@yahoo.com> wrote:
> I have a select statement that goes as follows:
>
> SELECT * FROM product prod, prod_alias pa, category cat, company co
> WHERE prod.catid = cat.catid
> AND prod.coid = co.coid
> AND prod.prodid = pa.prodid;
>
> If possible, I want to change the statement so that I get output regardless of whether there's a match between prod.prodid and pa.prodid. IOW, if there's a match between prod.prodid and pa.prodid, I want the output from both the product table and the prod_alias table. if there's no match, I still want the output from product table. Can I do this in one select statement?
This is what outer joins are used for. See
http://developer.postgresql.org/docs/postgres/sql-select.html
for the syntax and a very brief description of what they do.
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: Syntax question
@ 2006-05-26 16:41 A. Kretschmer <andreas.kretschmer@schollglas.com>
parent: John Taylor <d_low22003@yahoo.com>
2 siblings, 0 replies; 18+ messages in thread
From: A. Kretschmer @ 2006-05-26 16:41 UTC (permalink / raw)
To: pgsql-general
am 26.05.2006, um 9:09:25 -0700 mailte John Taylor folgendes:
> I have a select statement that goes as follows:
>
> SELECT * FROM product prod, prod_alias pa, category cat, company co
> WHERE prod.catid = cat.catid
> AND prod.coid = co.coid
> AND prod.prodid = pa.prodid;
>
> If possible, I want to change the statement so that I get output
> regardless of whether there's a match between prod.prodid and
> pa.prodid. IOW, if there's a match between prod.prodid and pa.prodid,
> I want the output from both the product table and the prod_alias
> table. if there's no match, I still want the output from product
> table. Can I do this in one select statement?
I think, you should read about 'left outer join'.
http://www.postgresql.org/docs/8.1/interactive/queries-table-expressions.html#QUERIES-FROM
HTH, Andreas
--
Andreas Kretschmer (Kontakt: siehe Header)
Heynitz: 035242/47215, D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
=== Schollglas Unternehmensgruppe ===
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: Syntax question
@ 2006-05-26 17:21 David Fetter <david@fetter.org>
parent: John Taylor <d_low22003@yahoo.com>
2 siblings, 0 replies; 18+ messages in thread
From: David Fetter @ 2006-05-26 17:21 UTC (permalink / raw)
To: John Taylor <d_low22003@yahoo.com>; +Cc: pgsql-general
On Fri, May 26, 2006 at 09:09:25AM -0700, John Taylor wrote:
> I have a select statement that goes as follows:
>
> SELECT * FROM product prod, prod_alias pa, category cat, company co
> WHERE prod.catid = cat.catid
> AND prod.coid = co.coid
> AND prod.prodid = pa.prodid;
>
> If possible, I want to change the statement so that I get output
> regardless of whether there's a match between prod.prodid and
> pa.prodid. IOW, if there's a match between prod.prodid and
> pa.prodid, I want the output from both the product table and the
> prod_alias table. if there's no match, I still want the output
> from product table. Can I do this in one select statement?
Yes :)
First, rewrite your query to make the JOINs explicit like this:
/* Rewritten query #1 (Q1) */
SELECT prod.*, pa.*, cat.*, co.* -- *Slightly* better than * :P
FROM
product prod
JOIN
prod_alias pa
ON (prod.prodid = pa.prodid)
JOIN
category cat
ON (prod.catid = cat.catid)
JOIN
company co
ON (prod.coid = co.coid)
Then look up LEFT JOIN in the OUTER JOIN part of the manual others
have pointed you to. What you'll come out with is something like
this:
/* Rewritten query #2 (Q2) */
SELECT prod.*, pa.*, cat.*, co.* -- *Slightly* better than * :P
FROM
product prod
LEFT JOIN
prod_alias pa
ON (prod.prodid = pa.prodid)
JOIN
category cat
ON (prod.catid = cat.catid)
JOIN
company co
ON (prod.coid = co.coid)
When you compart Q1 and Q2 side by side, you'll see that the only
difference between Q1 and Q2 above is the word LEFT.
HTH :)
Cheers,
D
--
David Fetter <david@fetter.org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter
Remember to vote!
^ permalink raw reply [nested|flat] 18+ messages in thread
* syntax question
@ 2021-06-03 18:58 Marc Millas <marc.millas@mokadb.com>
0 siblings, 1 reply; 18+ messages in thread
From: Marc Millas @ 2021-06-03 18:58 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Hi,
within a function, I want to create another function.
no pb.
but if I write:
declare bidule text;
begin
bidule:='myfunc';
create function bidule() ...
it does create a function named bidule and not myfunc.
so I am obviously missing something too obvious.
can someone help ?
thanks
Marc MILLAS
Senior Architect
+33607850334
www.mokadb.com
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: syntax question
@ 2021-06-03 19:01 Bruce Momjian <bruce@momjian.us>
parent: Marc Millas <marc.millas@mokadb.com>
0 siblings, 1 reply; 18+ messages in thread
From: Bruce Momjian @ 2021-06-03 19:01 UTC (permalink / raw)
To: Marc Millas <marc.millas@mokadb.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
On Thu, Jun 3, 2021 at 08:58:03PM +0200, Marc Millas wrote:
> Hi,
>
> within a function, I want to create another function.
> no pb.
> but if I write:
> declare bidule text;
> begin
> bidule:='myfunc';
> create function bidule() ...
>
>
> it does create a function named bidule and not myfunc.
> so I am obviously missing something too obvious.
You can't create functions inside of functions; same for procedures.
--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com
If only the physical world exists, free will is an illusion.
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: syntax question
@ 2021-06-03 19:11 Adrian Klaver <adrian.klaver@aklaver.com>
parent: Bruce Momjian <bruce@momjian.us>
0 siblings, 2 replies; 18+ messages in thread
From: Adrian Klaver @ 2021-06-03 19:11 UTC (permalink / raw)
To: Bruce Momjian <bruce@momjian.us>; Marc Millas <marc.millas@mokadb.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
On 6/3/21 12:01 PM, Bruce Momjian wrote:
> On Thu, Jun 3, 2021 at 08:58:03PM +0200, Marc Millas wrote:
>> Hi,
>>
>> within a function, I want to create another function.
>> no pb.
>> but if I write:
>> declare bidule text;
>> begin
>> bidule:='myfunc';
>> create function bidule() ...
>>
>>
>> it does create a function named bidule and not myfunc.
>> so I am obviously missing something too obvious.
>
> You can't create functions inside of functions; same for procedures.
>
Sure you can:
CREATE OR REPLACE FUNCTION public.test_fnc()
RETURNS void
LANGUAGE plpgsql
AS $function$
DECLARE
bidule text;
BEGIN
bidule:='myfunc';
EXECUTE 'create function ' || bidule || '() RETURNS void language
plpgsql AS $fnc$ BEGIN END; $fnc$ ';
END;
$function$
select test_fnc();
test_fnc
----------
\df myfunc
List of functions
Schema | Name | Result data type | Argument data types | Type
--------+--------+------------------+---------------------+------
public | myfunc | void | | func
Whether you should is another question.
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: syntax question
@ 2021-06-03 19:21 Tom Lane <tgl@sss.pgh.pa.us>
parent: Adrian Klaver <adrian.klaver@aklaver.com>
1 sibling, 2 replies; 18+ messages in thread
From: Tom Lane @ 2021-06-03 19:21 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Bruce Momjian <bruce@momjian.us>; Marc Millas <marc.millas@mokadb.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Adrian Klaver <adrian.klaver@aklaver.com> writes:
> On 6/3/21 12:01 PM, Bruce Momjian wrote:
>> On Thu, Jun 3, 2021 at 08:58:03PM +0200, Marc Millas wrote:
>>> within a function, I want to create another function.
>> You can't create functions inside of functions; same for procedures.
> Sure you can:
Yeah. The actual problem here is that Marc is expecting variable
substitution to occur within a utility (DDL) statement, which it
doesn't. The workaround is to build the command as a string and
use EXECUTE, as Adrian illustrated:
> EXECUTE 'create function ' || bidule || '() RETURNS void language
> plpgsql AS $fnc$ BEGIN END; $fnc$ ';
This is not terribly well explained in the existing docs. I tried
to improve the explanation awhile ago in HEAD:
https://www.postgresql.org/docs/devel/plpgsql-statements.html#PLPGSQL-STATEMENTS-GENERAL-SQL
regards, tom lane
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: syntax question
@ 2021-06-03 19:34 Bruce Momjian <bruce@momjian.us>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 18+ messages in thread
From: Bruce Momjian @ 2021-06-03 19:34 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; Marc Millas <marc.millas@mokadb.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
On Thu, Jun 3, 2021 at 03:21:15PM -0400, Tom Lane wrote:
> Adrian Klaver <adrian.klaver@aklaver.com> writes:
> > On 6/3/21 12:01 PM, Bruce Momjian wrote:
> >> On Thu, Jun 3, 2021 at 08:58:03PM +0200, Marc Millas wrote:
> >>> within a function, I want to create another function.
>
> >> You can't create functions inside of functions; same for procedures.
>
> > Sure you can:
>
> Yeah. The actual problem here is that Marc is expecting variable
> substitution to occur within a utility (DDL) statement, which it
> doesn't. The workaround is to build the command as a string and
> use EXECUTE, as Adrian illustrated:
>
> > EXECUTE 'create function ' || bidule || '() RETURNS void language
> > plpgsql AS $fnc$ BEGIN END; $fnc$ ';
>
> This is not terribly well explained in the existing docs. I tried
> to improve the explanation awhile ago in HEAD:
>
> https://www.postgresql.org/docs/devel/plpgsql-statements.html#PLPGSQL-STATEMENTS-GENERAL-SQL
Oh, I thought he wanted to declare a function inside the function that
could be called only by that function, like private functions in Oracle
packages can do. Yes, you can create a function that defines a function
that can be called later. I guess you could also create a function that
_conditionally_ creates a function that it can call itself too. My
point is that you can't create a function that has function scope ---
they all have schema scope.
--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com
If only the physical world exists, free will is an illusion.
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: syntax question
@ 2021-06-03 19:53 Marc Millas <marc.millas@mokadb.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 18+ messages in thread
From: Marc Millas @ 2021-06-03 19:53 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; Bruce Momjian <bruce@momjian.us>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
good reading, thanks
Marc MILLAS
Senior Architect
+33607850334
www.mokadb.com
On Thu, Jun 3, 2021 at 9:21 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Adrian Klaver <adrian.klaver@aklaver.com> writes:
> > On 6/3/21 12:01 PM, Bruce Momjian wrote:
> >> On Thu, Jun 3, 2021 at 08:58:03PM +0200, Marc Millas wrote:
> >>> within a function, I want to create another function.
>
> >> You can't create functions inside of functions; same for procedures.
>
> > Sure you can:
>
> Yeah. The actual problem here is that Marc is expecting variable
> substitution to occur within a utility (DDL) statement, which it
> doesn't. The workaround is to build the command as a string and
> use EXECUTE, as Adrian illustrated:
>
> > EXECUTE 'create function ' || bidule || '() RETURNS void language
> > plpgsql AS $fnc$ BEGIN END; $fnc$ ';
>
> This is not terribly well explained in the existing docs. I tried
> to improve the explanation awhile ago in HEAD:
>
>
> https://www.postgresql.org/docs/devel/plpgsql-statements.html#PLPGSQL-STATEMENTS-GENERAL-SQL
>
> regards, tom lane
>
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: syntax question
@ 2021-06-03 20:01 Marc Millas <marc.millas@mokadb.com>
parent: Adrian Klaver <adrian.klaver@aklaver.com>
1 sibling, 2 replies; 18+ messages in thread
From: Marc Millas @ 2021-06-03 20:01 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Bruce Momjian <bruce@momjian.us>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
thanks Adrian, exactly what I was missing :-)
about knowing if I should...
We have to create a set of triggers (insert, update, delete) within a huge
set of tables. and that list of tables, and structure of them can be
customized, maintained, ...
so we were looking for a standard script to automatize the building of the
whole thing, taking list of columns and constraints (for PK) directly from
pg_catalog.
Now it works :-)
but.. why do you ask that question ? is there any king of hidden wolf we
didnt see ?
Marc MILLAS
Senior Architect
+33607850334
www.mokadb.com
On Thu, Jun 3, 2021 at 9:11 PM Adrian Klaver <adrian.klaver@aklaver.com>
wrote:
> On 6/3/21 12:01 PM, Bruce Momjian wrote:
> > On Thu, Jun 3, 2021 at 08:58:03PM +0200, Marc Millas wrote:
> >> Hi,
> >>
> >> within a function, I want to create another function.
> >> no pb.
> >> but if I write:
> >> declare bidule text;
> >> begin
> >> bidule:='myfunc';
> >> create function bidule() ...
> >>
> >>
> >> it does create a function named bidule and not myfunc.
> >> so I am obviously missing something too obvious.
> >
> > You can't create functions inside of functions; same for procedures.
> >
>
> Sure you can:
>
> CREATE OR REPLACE FUNCTION public.test_fnc()
> RETURNS void
> LANGUAGE plpgsql
> AS $function$
> DECLARE
> bidule text;
> BEGIN
> bidule:='myfunc';
> EXECUTE 'create function ' || bidule || '() RETURNS void language
> plpgsql AS $fnc$ BEGIN END; $fnc$ ';
> END;
>
>
> $function$
>
> select test_fnc();
> test_fnc
> ----------
>
> \df myfunc
> List of functions
> Schema | Name | Result data type | Argument data types | Type
> --------+--------+------------------+---------------------+------
> public | myfunc | void | | func
>
>
> Whether you should is another question.
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: syntax question
@ 2021-06-03 20:22 David G. Johnston <david.g.johnston@gmail.com>
parent: Marc Millas <marc.millas@mokadb.com>
1 sibling, 1 reply; 18+ messages in thread
From: David G. Johnston @ 2021-06-03 20:22 UTC (permalink / raw)
To: Marc Millas <marc.millas@mokadb.com>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; Bruce Momjian <bruce@momjian.us>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
On Thu, Jun 3, 2021 at 1:02 PM Marc Millas <marc.millas@mokadb.com> wrote:
> about knowing if I should...
> We have to create a set of triggers (insert, update, delete) within a huge
> set of tables. and that list of tables, and structure of them can be
> customized, maintained, ...
> so we were looking for a standard script to automatize the building of the
> whole thing, taking list of columns and constraints (for PK) directly from
> pg_catalog.
> Now it works :-)
>
> but.. why do you ask that question ? is there any king of hidden wolf we
> didnt see ?
>
Having done this (building a - limited - code generator framework using
bash+psql+plpgsql) I will say that doing so using pl/pgsql, while appealing
from "no extra tooling needed" perspective, doesn't play to pl/pgsql's
strengths. Using a different language to generate SQL script files, which
can then be executed, is probably a better way to go - if you have a
different language you can build upon (i.e., not a shell scripting language
like bash).
In particular, plpgsql nested strings are not fun to work with in any
significant volume.
David J.
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: syntax question
@ 2021-06-03 20:55 Marc Millas <marc.millas@mokadb.com>
parent: David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 0 replies; 18+ messages in thread
From: Marc Millas @ 2021-06-03 20:55 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; Bruce Momjian <bruce@momjian.us>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
I take note of this.
thanks
Marc MILLAS
Senior Architect
+33607850334
www.mokadb.com
On Thu, Jun 3, 2021 at 10:23 PM David G. Johnston <
david.g.johnston@gmail.com> wrote:
> On Thu, Jun 3, 2021 at 1:02 PM Marc Millas <marc.millas@mokadb.com> wrote:
>
>> about knowing if I should...
>> We have to create a set of triggers (insert, update, delete) within a
>> huge set of tables. and that list of tables, and structure of them can be
>> customized, maintained, ...
>> so we were looking for a standard script to automatize the building of
>> the whole thing, taking list of columns and constraints (for PK) directly
>> from pg_catalog.
>> Now it works :-)
>>
>> but.. why do you ask that question ? is there any king of hidden wolf we
>> didnt see ?
>>
>
> Having done this (building a - limited - code generator framework using
> bash+psql+plpgsql) I will say that doing so using pl/pgsql, while appealing
> from "no extra tooling needed" perspective, doesn't play to pl/pgsql's
> strengths. Using a different language to generate SQL script files, which
> can then be executed, is probably a better way to go - if you have a
> different language you can build upon (i.e., not a shell scripting language
> like bash).
>
> In particular, plpgsql nested strings are not fun to work with in any
> significant volume.
>
> David J.
>
>
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: syntax question
@ 2021-06-03 21:07 Guyren Howe <guyren@gmail.com>
parent: Bruce Momjian <bruce@momjian.us>
0 siblings, 0 replies; 18+ messages in thread
From: Guyren Howe @ 2021-06-03 21:07 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
I know it would be non-standard, but I would love to see Postgres support the likes of nested functions.
I know that would be non-standard, but Postgres has lots of non-standard features that make it more like a real programming language and considerably more productive.
On Jun 3, 2021, 12:34 -0700, Bruce Momjian <bruce@momjian.us>, wrote:
> On Thu, Jun 3, 2021 at 03:21:15PM -0400, Tom Lane wrote:
> > Adrian Klaver <adrian.klaver@aklaver.com> writes:
> > > On 6/3/21 12:01 PM, Bruce Momjian wrote:
> > > > On Thu, Jun 3, 2021 at 08:58:03PM +0200, Marc Millas wrote:
> > > > > within a function, I want to create another function.
> >
> > > > You can't create functions inside of functions; same for procedures.
> >
> > > Sure you can:
> >
> > Yeah. The actual problem here is that Marc is expecting variable
> > substitution to occur within a utility (DDL) statement, which it
> > doesn't. The workaround is to build the command as a string and
> > use EXECUTE, as Adrian illustrated:
> >
> > > EXECUTE 'create function ' || bidule || '() RETURNS void language
> > > plpgsql AS $fnc$ BEGIN END; $fnc$ ';
> >
> > This is not terribly well explained in the existing docs. I tried
> > to improve the explanation awhile ago in HEAD:
> >
> > https://www.postgresql.org/docs/devel/plpgsql-statements.html#PLPGSQL-STATEMENTS-GENERAL-SQL
>
> Oh, I thought he wanted to declare a function inside the function that
> could be called only by that function, like private functions in Oracle
> packages can do. Yes, you can create a function that defines a function
> that can be called later. I guess you could also create a function that
> _conditionally_ creates a function that it can call itself too. My
> point is that you can't create a function that has function scope ---
> they all have schema scope.
>
> --
> Bruce Momjian <bruce@momjian.us> https://momjian.us
> EDB https://enterprisedb.com
>
> If only the physical world exists, free will is an illusion.
>
>
>
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: syntax question
@ 2021-06-03 21:17 Adrian Klaver <adrian.klaver@aklaver.com>
parent: Marc Millas <marc.millas@mokadb.com>
1 sibling, 1 reply; 18+ messages in thread
From: Adrian Klaver @ 2021-06-03 21:17 UTC (permalink / raw)
To: Marc Millas <marc.millas@mokadb.com>; +Cc: Bruce Momjian <bruce@momjian.us>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
On 6/3/21 1:01 PM, Marc Millas wrote:
> thanks Adrian, exactly what I was missing :-)
>
> about knowing if I should...
> We have to create a set of triggers (insert, update, delete) within a
> huge set of tables. and that list of tables, and structure of them can
> be customized, maintained, ...
> so we were looking for a standard script to automatize the building of
> the whole thing, taking list of columns and constraints (for PK)
> directly from pg_catalog.
> Now it works :-)
>
> but.. why do you ask that question ? is there any king of hidden wolf we
> didnt see ?
See David Johnston's answer. Nested quoting will drive you to drink(or
drink more):)
>
>
> Marc MILLAS
> Senior Architect
> +33607850334
> www.mokadb.com <http://www.mokadb.com;
>
>
>
> On Thu, Jun 3, 2021 at 9:11 PM Adrian Klaver <adrian.klaver@aklaver.com
> <mailto:adrian.klaver@aklaver.com>> wrote:
>
> On 6/3/21 12:01 PM, Bruce Momjian wrote:
> > On Thu, Jun 3, 2021 at 08:58:03PM +0200, Marc Millas wrote:
> >> Hi,
> >>
> >> within a function, I want to create another function.
> >> no pb.
> >> but if I write:
> >> declare bidule text;
> >> begin
> >> bidule:='myfunc';
> >> create function bidule() ...
> >>
> >>
> >> it does create a function named bidule and not myfunc.
> >> so I am obviously missing something too obvious.
> >
> > You can't create functions inside of functions; same for procedures.
> >
>
> Sure you can:
>
> CREATE OR REPLACE FUNCTION public.test_fnc()
> RETURNS void
> LANGUAGE plpgsql
> AS $function$
> DECLARE
> bidule text;
> BEGIN
> bidule:='myfunc';
> EXECUTE 'create function ' || bidule || '() RETURNS void language
> plpgsql AS $fnc$ BEGIN END; $fnc$ ';
> END;
>
>
> $function$
>
> select test_fnc();
> test_fnc
> ----------
>
> \df myfunc
> List of functions
> Schema | Name | Result data type | Argument data types | Type
> --------+--------+------------------+---------------------+------
> public | myfunc | void | | func
>
>
> Whether you should is another question.
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: syntax question
@ 2021-06-03 21:43 Marc Millas <marc.millas@mokadb.com>
parent: Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 0 replies; 18+ messages in thread
From: Marc Millas @ 2021-06-03 21:43 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Bruce Momjian <bruce@momjian.us>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
no pb: I am french, so quite skilled on that topic :-)
there is only 50 bottles of various malt on the presentoir close to my desk
so I must stay reasonnable :-)
Marc MILLAS
Senior Architect
+33607850334
www.mokadb.com
On Thu, Jun 3, 2021 at 11:17 PM Adrian Klaver <adrian.klaver@aklaver.com>
wrote:
> On 6/3/21 1:01 PM, Marc Millas wrote:
> > thanks Adrian, exactly what I was missing :-)
> >
> > about knowing if I should...
> > We have to create a set of triggers (insert, update, delete) within a
> > huge set of tables. and that list of tables, and structure of them can
> > be customized, maintained, ...
> > so we were looking for a standard script to automatize the building of
> > the whole thing, taking list of columns and constraints (for PK)
> > directly from pg_catalog.
> > Now it works :-)
> >
> > but.. why do you ask that question ? is there any king of hidden wolf we
> > didnt see ?
>
> See David Johnston's answer. Nested quoting will drive you to drink(or
> drink more):)
>
>
> >
> >
> > Marc MILLAS
> > Senior Architect
> > +33607850334
> > www.mokadb.com <http://www.mokadb.com;
> >
> >
> >
> > On Thu, Jun 3, 2021 at 9:11 PM Adrian Klaver <adrian.klaver@aklaver.com
> > <mailto:adrian.klaver@aklaver.com>> wrote:
> >
> > On 6/3/21 12:01 PM, Bruce Momjian wrote:
> > > On Thu, Jun 3, 2021 at 08:58:03PM +0200, Marc Millas wrote:
> > >> Hi,
> > >>
> > >> within a function, I want to create another function.
> > >> no pb.
> > >> but if I write:
> > >> declare bidule text;
> > >> begin
> > >> bidule:='myfunc';
> > >> create function bidule() ...
> > >>
> > >>
> > >> it does create a function named bidule and not myfunc.
> > >> so I am obviously missing something too obvious.
> > >
> > > You can't create functions inside of functions; same for
> procedures.
> > >
> >
> > Sure you can:
> >
> > CREATE OR REPLACE FUNCTION public.test_fnc()
> > RETURNS void
> > LANGUAGE plpgsql
> > AS $function$
> > DECLARE
> > bidule text;
> > BEGIN
> > bidule:='myfunc';
> > EXECUTE 'create function ' || bidule || '() RETURNS void language
> > plpgsql AS $fnc$ BEGIN END; $fnc$ ';
> > END;
> >
> >
> > $function$
> >
> > select test_fnc();
> > test_fnc
> > ----------
> >
> > \df myfunc
> > List of functions
> > Schema | Name | Result data type | Argument data types | Type
> > --------+--------+------------------+---------------------+------
> > public | myfunc | void | | func
> >
> >
> > Whether you should is another question.
> >
> >
> > --
> > Adrian Klaver
> > adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>
> >
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>
^ permalink raw reply [nested|flat] 18+ messages in thread
end of thread, other threads:[~2021-06-03 21:43 UTC | newest]
Thread overview: 18+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-07-06 22:42 Syntax question Tony Li <tony.li@tony.li>
2004-07-07 01:15 ` David Helgason <david@uti.is>
2006-05-26 16:09 Syntax question John Taylor <d_low22003@yahoo.com>
2006-05-26 16:35 ` Bruno Wolff III <bruno@wolff.to>
2006-05-26 16:41 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
2006-05-26 17:21 ` David Fetter <david@fetter.org>
2021-06-03 18:58 syntax question Marc Millas <marc.millas@mokadb.com>
2021-06-03 19:01 ` Re: syntax question Bruce Momjian <bruce@momjian.us>
2021-06-03 19:11 ` Re: syntax question Adrian Klaver <adrian.klaver@aklaver.com>
2021-06-03 19:21 ` Re: syntax question Tom Lane <tgl@sss.pgh.pa.us>
2021-06-03 19:34 ` Re: syntax question Bruce Momjian <bruce@momjian.us>
2021-06-03 21:07 ` Re: syntax question Guyren Howe <guyren@gmail.com>
2021-06-03 19:53 ` Re: syntax question Marc Millas <marc.millas@mokadb.com>
2021-06-03 20:01 ` Re: syntax question Marc Millas <marc.millas@mokadb.com>
2021-06-03 20:22 ` Re: syntax question David G. Johnston <david.g.johnston@gmail.com>
2021-06-03 20:55 ` Re: syntax question Marc Millas <marc.millas@mokadb.com>
2021-06-03 21:17 ` Re: syntax question Adrian Klaver <adrian.klaver@aklaver.com>
2021-06-03 21:43 ` Re: syntax question Marc Millas <marc.millas@mokadb.com>
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