Add schema to the query

Started by Igor Korotalmost 8 years ago6 messagesgeneral
Jump to latest
#1Igor Korot
ikorot01@gmail.com

Hi, ALL,

Is there an easy way to add the schema to the following query:

SELECT u.usename FROM pg_class c, pg_user u WHERE u.usesysid =
c.relowner AND relname = ?

Thank you.

#2Melvin Davidson
melvin6925@gmail.com
In reply to: Igor Korot (#1)
Re: Add schema to the query

On Sun, May 6, 2018 at 10:19 PM, Igor Korot <ikorot01@gmail.com> wrote:

Hi, ALL,

Is there an easy way to add the schema to the following query:

SELECT u.usename FROM pg_class c, pg_user u WHERE u.usesysid =
c.relowner AND relname = ?

Thank you.

Is there an easy way to add the schema to the following query:

You mean like this?
SELECT u.usename,
*n.nspname AS schema*
FROM pg_class c
*JOIN pg_namespace n ON n.oid = c.relnamespace,*
pg_user u
WHERE u.usesysid = c.relowner
AND relname = ?

--
*Melvin Davidson*
*Maj. Database & Exploration Specialist*
*Universe Exploration Command – UXC*
Employment by invitation only!

#3Melvin Davidson
melvin6925@gmail.com
In reply to: Melvin Davidson (#2)
Re: Add schema to the query

On Sun, May 6, 2018 at 10:33 PM, Melvin Davidson <melvin6925@gmail.com>
wrote:

On Sun, May 6, 2018 at 10:19 PM, Igor Korot <ikorot01@gmail.com> wrote:

Hi, ALL,

Is there an easy way to add the schema to the following query:

SELECT u.usename FROM pg_class c, pg_user u WHERE u.usesysid =
c.relowner AND relname = ?

Thank you.

Is there an easy way to add the schema to the following query:

You mean like this?
SELECT u.usename,
*n.nspname AS schema*
FROM pg_class c
*JOIN pg_namespace n ON n.oid = c.relnamespace,*
pg_user u
WHERE u.usesysid = c.relowner
AND relname = ?

--
*Melvin Davidson*
*Maj. Database & Exploration Specialist*
*Universe Exploration Command – UXC*
Employment by invitation only!

OR do you mean like this?
SELECT u.usename
FROM pg_class c
*JOIN pg_namespace n ON n.oid = c.relnamespace, *
pg_user u
WHERE u.usesysid = c.relowner
AND relname = ?

* AND n.nspname = 'public'*

--
*Melvin Davidson*
*Maj. Database & Exploration Specialist*
*Universe Exploration Command – UXC*
Employment by invitation only!

#4Igor Korot
ikorot01@gmail.com
In reply to: Melvin Davidson (#3)
Re: Add schema to the query

Hi, Melvin,

On Sun, May 6, 2018 at 9:37 PM, Melvin Davidson <melvin6925@gmail.com> wrote:

On Sun, May 6, 2018 at 10:33 PM, Melvin Davidson <melvin6925@gmail.com>
wrote:

On Sun, May 6, 2018 at 10:19 PM, Igor Korot <ikorot01@gmail.com> wrote:

Hi, ALL,

Is there an easy way to add the schema to the following query:

SELECT u.usename FROM pg_class c, pg_user u WHERE u.usesysid =
c.relowner AND relname = ?

Thank you.

Is there an easy way to add the schema to the following query:

You mean like this?
SELECT u.usename,
n.nspname AS schema
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace,
pg_user u
WHERE u.usesysid = c.relowner
AND relname = ?

--
Melvin Davidson
Maj. Database & Exploration Specialist
Universe Exploration Command – UXC
Employment by invitation only!

OR do you mean like this?
SELECT u.usename
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace,
pg_user u
WHERE u.usesysid = c.relowner
AND relname = ?
AND n.nspname = 'public'

Sorry needed to filter on the schema + table.

So, thank you.

Show quoted text

--
Melvin Davidson
Maj. Database & Exploration Specialist
Universe Exploration Command – UXC
Employment by invitation only!

#5Rob Sargent
robjsargent@gmail.com
In reply to: Igor Korot (#1)
Re: Add schema to the query

On May 6, 2018, at 8:19 PM, Igor Korot <ikorot01@gmail.com> wrote:

Hi, ALL,

Is there an easy way to add the schema to the following query:

SELECT u.usename FROM pg_class c, pg_user u WHERE u.usesysid =
c.relowner AND relname = ?

Thank you.

Are you looking for the owner of a particular schema.tablename?

#6Igor Korot
ikorot01@gmail.com
In reply to: Rob Sargent (#5)
Re: Add schema to the query

Rob,

On Sun, May 6, 2018 at 11:54 PM, Rob Sargent <robjsargent@gmail.com> wrote:

On May 6, 2018, at 8:19 PM, Igor Korot <ikorot01@gmail.com> wrote:

Hi, ALL,

Is there an easy way to add the schema to the following query:

SELECT u.usename FROM pg_class c, pg_user u WHERE u.usesysid =
c.relowner AND relname = ?

Thank you.

Are you looking for the owner of a particular schema.tablename?

Yes, I am.

That;s what I ended up with:

SELECT u.usename FROM pg_class c, pg_user u, pg_namespace n WHERE
n.oid = c.relnamespace AND u.usesysid = c.relowner AND n.nspname = ?
AND relname = ?

Thank you.