Обсуждение: Can we use sql language to create a function in Postgres?

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

Can we use sql language to create a function in Postgres?

От
Shaozhong SHI
Дата:
I was given an Oracle script.  Can we use sql language to create a function in Postgres?

Regards,

David

Re: Can we use sql language to create a function in Postgres?

От
Ray O'Donnell
Дата:
On 05/01/2022 11:04, Shaozhong SHI wrote:
> I was given an Oracle script.  Can we use sql language to create a 
> function in Postgres?

Yes, absolutely:

create function my_function(...)
as
$$
   select.....
$$
language sql;


Is this what you mean?


Ray.


-- 
Raymond O'Donnell // Galway // Ireland
ray@rodonnell.ie



Re: Can we use sql language to create a function in Postgres?

От
Ray O'Donnell
Дата:
On 05/01/2022 11:08, Ray O'Donnell wrote:
> On 05/01/2022 11:04, Shaozhong SHI wrote:
>> I was given an Oracle script.  Can we use sql language to create a 
>> function in Postgres?
> 
> Yes, absolutely:
> 
> create function my_function(...)
> as
> $$
>    select.....
> $$
> language sql;

Should have added the link to the docs:

https://www.postgresql.org/docs/14/server-programming.html

Ray.


-- 
Raymond O'Donnell // Galway // Ireland
ray@rodonnell.ie



Re: Can we use sql language to create a function in Postgres?

От
hubert depesz lubaczewski
Дата:
On Wed, Jan 05, 2022 at 11:04:34AM +0000, Shaozhong SHI wrote:
> I was given an Oracle script.  Can we use sql language to create a function
> in Postgres?

Sure:

create function z() returns int4 language sql as $$
select 123;
$$;

depesz



Re: Can we use sql language to create a function in Postgres?

От
Shaozhong SHI
Дата:
If so, can we use Oracle SQL script in DO block?

Does this mean that all Oracle SQL can be used in Postgres?

Regards,

David

On Wed, 5 Jan 2022 at 11:12, hubert depesz lubaczewski <depesz@depesz.com> wrote:
On Wed, Jan 05, 2022 at 11:04:34AM +0000, Shaozhong SHI wrote:
> I was given an Oracle script.  Can we use sql language to create a function
> in Postgres?

Sure:

create function z() returns int4 language sql as $$
select 123;
$$;

depesz

Re: Can we use sql language to create a function in Postgres?

От
Shaozhong SHI
Дата:
Any online documentation or examples for using Oracle SQL in Postgres?

Regards,

David

On Wed, 5 Jan 2022 at 11:22, Shaozhong SHI <shishaozhong@gmail.com> wrote:
If so, can we use Oracle SQL script in DO block?

Does this mean that all Oracle SQL can be used in Postgres?

Regards,

David

On Wed, 5 Jan 2022 at 11:12, hubert depesz lubaczewski <depesz@depesz.com> wrote:
On Wed, Jan 05, 2022 at 11:04:34AM +0000, Shaozhong SHI wrote:
> I was given an Oracle script.  Can we use sql language to create a function
> in Postgres?

Sure:

create function z() returns int4 language sql as $$
select 123;
$$;

depesz

Re: Can we use sql language to create a function in Postgres?

От
hubert depesz lubaczewski
Дата:
On Wed, Jan 05, 2022 at 11:22:34AM +0000, Shaozhong SHI wrote:
> If so, can we use Oracle SQL script in DO block?
> 
> Does this mean that all Oracle SQL can be used in Postgres?

I highly doubt that.
But - I used oracle last time like 2 years ago, so the only thing I can
tell you: TRY.
instead of asking if "something vague wll work" just try. it will work,
or not work, but I can't guess what you have in this "oracle sql" and
whether this particular bit of sql will be cross-plaftorm enough to
execute (or even parse) in pg.

depesz



Re: Can we use sql language to create a function in Postgres?

От
Merlin Moncure
Дата:
On Wed, Jan 5, 2022 at 5:27 AM Shaozhong SHI <shishaozhong@gmail.com> wrote:
>
> Any online documentation or examples for using Oracle SQL in Postgres?

FYI there are commercial offerings (in particular, EDB, which I am not
affiliated with) that minimize compatibility concerns with oracle.  If
doing this by hand, utilizing the lists (which SPECIFIC questions) and
other internet resources is the way to go. There may be some guides,
but the SQL language and other nuance is moving fast, so try to get
contemporary help if possible.  Conversion to postgres will work, and
what you are doing is a good idea.

merlin