Postgresql there is an entry for table but it cannot be referenced from this part of the query
up vote
0
down vote
favorite
I have a problem with my select query
select distinct l.*, tmp_addr.address from l.lic as l
left join l.hou as h on l.lic_id=h.lic_guid
left join l.org as o on o.org_id=l.org_guid
LEFT JOIN (
SELECT address
FROM dblink('sm_d','SELECT * FROM
sm.func_get(' || COALESCE(QUOTE_LITERAL(h.hguid), 'NULL') || ', TRUE, ''sm'')')
AS addr(full_address TEXT, address_guid TEXT)
) AS tmp_addr ON h.house_address_guid=tmp_addr.address_guid
where o.root_organization_ref_guid='b26961ae-f015' and l.status <> 'INACTIVE' and l.version='true' and h.registry_status_type='INCLUDED';
SQL Error [42P01]: ERROR: invalid reference to FROM-clause entry for table "h"
There is an entry for table "h", but it cannot be referenced from this part of the query.
Position: 348
sql postgresql
add a comment |
up vote
0
down vote
favorite
I have a problem with my select query
select distinct l.*, tmp_addr.address from l.lic as l
left join l.hou as h on l.lic_id=h.lic_guid
left join l.org as o on o.org_id=l.org_guid
LEFT JOIN (
SELECT address
FROM dblink('sm_d','SELECT * FROM
sm.func_get(' || COALESCE(QUOTE_LITERAL(h.hguid), 'NULL') || ', TRUE, ''sm'')')
AS addr(full_address TEXT, address_guid TEXT)
) AS tmp_addr ON h.house_address_guid=tmp_addr.address_guid
where o.root_organization_ref_guid='b26961ae-f015' and l.status <> 'INACTIVE' and l.version='true' and h.registry_status_type='INCLUDED';
SQL Error [42P01]: ERROR: invalid reference to FROM-clause entry for table "h"
There is an entry for table "h", but it cannot be referenced from this part of the query.
Position: 348
sql postgresql
distinct l.*
looks strange. That usually is an indication that you don't want a join but a sub-select with an EXISTS condition.
– a_horse_with_no_name
Nov 13 at 6:51
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a problem with my select query
select distinct l.*, tmp_addr.address from l.lic as l
left join l.hou as h on l.lic_id=h.lic_guid
left join l.org as o on o.org_id=l.org_guid
LEFT JOIN (
SELECT address
FROM dblink('sm_d','SELECT * FROM
sm.func_get(' || COALESCE(QUOTE_LITERAL(h.hguid), 'NULL') || ', TRUE, ''sm'')')
AS addr(full_address TEXT, address_guid TEXT)
) AS tmp_addr ON h.house_address_guid=tmp_addr.address_guid
where o.root_organization_ref_guid='b26961ae-f015' and l.status <> 'INACTIVE' and l.version='true' and h.registry_status_type='INCLUDED';
SQL Error [42P01]: ERROR: invalid reference to FROM-clause entry for table "h"
There is an entry for table "h", but it cannot be referenced from this part of the query.
Position: 348
sql postgresql
I have a problem with my select query
select distinct l.*, tmp_addr.address from l.lic as l
left join l.hou as h on l.lic_id=h.lic_guid
left join l.org as o on o.org_id=l.org_guid
LEFT JOIN (
SELECT address
FROM dblink('sm_d','SELECT * FROM
sm.func_get(' || COALESCE(QUOTE_LITERAL(h.hguid), 'NULL') || ', TRUE, ''sm'')')
AS addr(full_address TEXT, address_guid TEXT)
) AS tmp_addr ON h.house_address_guid=tmp_addr.address_guid
where o.root_organization_ref_guid='b26961ae-f015' and l.status <> 'INACTIVE' and l.version='true' and h.registry_status_type='INCLUDED';
SQL Error [42P01]: ERROR: invalid reference to FROM-clause entry for table "h"
There is an entry for table "h", but it cannot be referenced from this part of the query.
Position: 348
sql postgresql
sql postgresql
asked Nov 13 at 5:17
Sam Kilanoff
477
477
distinct l.*
looks strange. That usually is an indication that you don't want a join but a sub-select with an EXISTS condition.
– a_horse_with_no_name
Nov 13 at 6:51
add a comment |
distinct l.*
looks strange. That usually is an indication that you don't want a join but a sub-select with an EXISTS condition.
– a_horse_with_no_name
Nov 13 at 6:51
distinct l.*
looks strange. That usually is an indication that you don't want a join but a sub-select with an EXISTS condition.– a_horse_with_no_name
Nov 13 at 6:51
distinct l.*
looks strange. That usually is an indication that you don't want a join but a sub-select with an EXISTS condition.– a_horse_with_no_name
Nov 13 at 6:51
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
This seems really weird:
select distinct l.*, tmp_addr.address
FROM l.lic as l
left join l.hou as h on l.lic_id=h.lic_guid
left join l.org as o on o.org_id=l.org_guid
l.lic as l
-- You are setting an alias for LIC
table as l
left join l.hou as h
-- Now, when you say l.hou
, it means hou
is a column from table l
. But you are using it as a table.
left join l.org as o
-- Same problem as above.
So, if l
is a schema in your database where these tables are stored, I suggest you to use another alias name than l
.
If l
is not a schema, just remove l
from l.hou
and l.org
. Instead say, hou
and org
.
This should fix the error. Let me know if this helps.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
This seems really weird:
select distinct l.*, tmp_addr.address
FROM l.lic as l
left join l.hou as h on l.lic_id=h.lic_guid
left join l.org as o on o.org_id=l.org_guid
l.lic as l
-- You are setting an alias for LIC
table as l
left join l.hou as h
-- Now, when you say l.hou
, it means hou
is a column from table l
. But you are using it as a table.
left join l.org as o
-- Same problem as above.
So, if l
is a schema in your database where these tables are stored, I suggest you to use another alias name than l
.
If l
is not a schema, just remove l
from l.hou
and l.org
. Instead say, hou
and org
.
This should fix the error. Let me know if this helps.
add a comment |
up vote
0
down vote
This seems really weird:
select distinct l.*, tmp_addr.address
FROM l.lic as l
left join l.hou as h on l.lic_id=h.lic_guid
left join l.org as o on o.org_id=l.org_guid
l.lic as l
-- You are setting an alias for LIC
table as l
left join l.hou as h
-- Now, when you say l.hou
, it means hou
is a column from table l
. But you are using it as a table.
left join l.org as o
-- Same problem as above.
So, if l
is a schema in your database where these tables are stored, I suggest you to use another alias name than l
.
If l
is not a schema, just remove l
from l.hou
and l.org
. Instead say, hou
and org
.
This should fix the error. Let me know if this helps.
add a comment |
up vote
0
down vote
up vote
0
down vote
This seems really weird:
select distinct l.*, tmp_addr.address
FROM l.lic as l
left join l.hou as h on l.lic_id=h.lic_guid
left join l.org as o on o.org_id=l.org_guid
l.lic as l
-- You are setting an alias for LIC
table as l
left join l.hou as h
-- Now, when you say l.hou
, it means hou
is a column from table l
. But you are using it as a table.
left join l.org as o
-- Same problem as above.
So, if l
is a schema in your database where these tables are stored, I suggest you to use another alias name than l
.
If l
is not a schema, just remove l
from l.hou
and l.org
. Instead say, hou
and org
.
This should fix the error. Let me know if this helps.
This seems really weird:
select distinct l.*, tmp_addr.address
FROM l.lic as l
left join l.hou as h on l.lic_id=h.lic_guid
left join l.org as o on o.org_id=l.org_guid
l.lic as l
-- You are setting an alias for LIC
table as l
left join l.hou as h
-- Now, when you say l.hou
, it means hou
is a column from table l
. But you are using it as a table.
left join l.org as o
-- Same problem as above.
So, if l
is a schema in your database where these tables are stored, I suggest you to use another alias name than l
.
If l
is not a schema, just remove l
from l.hou
and l.org
. Instead say, hou
and org
.
This should fix the error. Let me know if this helps.
answered Nov 13 at 6:03
Mayank Porwal
2,7221620
2,7221620
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274265%2fpostgresql-there-is-an-entry-for-table-but-it-cannot-be-referenced-from-this-par%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
distinct l.*
looks strange. That usually is an indication that you don't want a join but a sub-select with an EXISTS condition.– a_horse_with_no_name
Nov 13 at 6:51