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

Started by Shaozhong SHIover 4 years ago8 messagesgeneral
Jump to latest
#1Shaozhong SHI
shishaozhong@gmail.com

I was given an Oracle script. Can we use sql language to create a function
in Postgres?

Regards,

David

#2Ray O'Donnell
ray@rodonnell.ie
In reply to: Shaozhong SHI (#1)
Re: Can we use sql language to create a function in Postgres?

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

#3Ray O'Donnell
ray@rodonnell.ie
In reply to: Ray O'Donnell (#2)
Re: Can we use sql language to create a function in Postgres?

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

In reply to: Shaozhong SHI (#1)
Re: Can we use sql language to create a function in Postgres?

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

#5Shaozhong SHI
shishaozhong@gmail.com
In reply to: hubert depesz lubaczewski (#4)
Re: Can we use sql language to create a function in Postgres?

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:

Show quoted text

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

#6Shaozhong SHI
shishaozhong@gmail.com
In reply to: Shaozhong SHI (#5)
Re: Can we use sql language to create a function in Postgres?

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:

Show quoted text

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

In reply to: Shaozhong SHI (#5)
Re: Can we use sql language to create a function in Postgres?

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

#8Merlin Moncure
mmoncure@gmail.com
In reply to: Shaozhong SHI (#6)
Re: Can we use sql language to create a function in Postgres?

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