Обсуждение: YNT: Re: [SQL] Using bind variable within BEGIN END

Поиск
Список
Период
Сортировка

YNT: Re: [SQL] Using bind variable within BEGIN END

От
gulsumramazanoglu
Дата:
David hi, if PostgreSQL doesnt have stored procedures and function can only be used by a SQL command, so we cannot make a call to an SQL script (of any kind, name it procedure or something) directly from a HLL program.. do i understand correctly?



Samsung cihazımdan gönderildi


-------- Orjinal mesaj --------
Kimden: "David G. Johnston" <david.g.johnston@gmail.com>
Tarih: 2 06 2017 9:21 PM (GMT+02:00)
Alıcı: anand086 <anand086@gmail.com>
Cc: pgsql-sql@postgresql.org
Konu: Re: [SQL] Using bind variable within BEGIN END

On Friday, June 2, 2017, anand086 <anand086@gmail.com> wrote:
Another example where we are getting the same error is from the call of the
below code --

ctx.update(""
                                                                + "begin \n"
                                                                + "
access.register_type( \n"
                                                                + "
p_entity_system                 => ?, \n"
                                                                + "
p_entity_type                      => ?, \n"
                                                                + "
p_attribute_name             => ?, \n"
                                                                + "
p_creator_id                        => ?, \n"
                                                                + "
p_description                       => ? \n"
                                                                + " );"
                                                                + "end;",
                                                                systemName,
                                                                entityType,

attributeName,
                                                                creatorID,

attributeDescription);


access.register_type is a function


PostgreSQL doesn't alllow named arguments when calling functions and function calls must be part of a SQL statement: select func(?,?,?,?.?);  this applied even to functions that do not return results.  IOW, PostgreSQL doesn't have stored procedures.

David J.

Re: [SQL] Using bind variable within BEGIN END

От
"David G. Johnston"
Дата:
On Friday, June 2, 2017, gulsumramazanoglu <gulsumramazanoglu@gmail.com> wrote:
David hi, if PostgreSQL doesnt have stored procedures and function can only be used by a SQL command, so we cannot make a call to an SQL script (of any kind, name it procedure or something) directly from a HLL program.. do i understand correctly?

I don't think so but I cannot figure out what your actual confusion is.  Write a function.  Execute a statement that invokes the function.  Remain connected until the function returns.  Learn whether it completed successfully or not and react accordingly. Move on in your HLL (higher level language?) code.

The term procedure in sql often implies autonomous which client invoked code cannot presently do (i.e., disconnect the connection after initiating the code but before it completes).

Your syntax issues are mostly about not having read the right sections of the docs pertaining to those syntactic issues.  Once you get past that you should be able to do most things that you can imagine.

David J.