I am new to postgres. I am trying to make the following query dynamic for different tables.
SELECT DISTINCT jsonb_object_keys(elements -> 'elements') AS individual_element
FROM Table1
I have 30 different tables on which I need to run this query but not sure how to do that in postgres (using pgAdmin4). Is this possible? Please help.
Thanks
-MS
Related
I have joined two tables and fetched data using Postgres source connector. But every time it gave the same issue i.e.
I have run the same query in Postgres and it runs without any issue. Is fetching data by joining tables not possible in Kafka?
I solve this issue by using the concept of the subquery. The problem was that
when I use an alias, the alias column is interpreted as a whole as a column name and therefore the problem occurs. Here goes my query:
select * from (select p.\"Id\" as \"p_Id\", p.\"CreatedDate\" as p_createddate, p.\"ClassId\" as p_classid, c.\"Id\" as c_id, c.\"CreatedDate\" as c_createddate, c.\"ClassId\" as c_classid from \"PolicyIssuance\" p left join \"ClassDetails\" c on p.\"DocumentNumber\" = c.\"DocumentNo\") as result"
Anyone know what is the ORM function for joining multiple db tables in ERPNext?
I need query result from 2 DB tables join using script report
*I don't need query report answer since i already have it. I only looking for an example do it using script report
Frappe currently doesn't have ORM support for joining tables. You might have to use frappe.db.sql for the time being.
data = frappe.db.sql(
"""
select tb1.name from tabTable1 as tb1
left join tabTable2 as tb2 on tb1.name = tb2.employee_name;
"""
);
return data
I'd like to query postgresql view via presto. I've found some old links/notes that it should be possible. Unfortunately I don't have any views listed in SHOW TABLES command and when I tried to query data select cnt from umcount I got Table 'public.umcount' not found. How to query views then?
I'm using Presto 0.205
You can try out these queries first:
show schemas from <connector_name>
show tables from <connector_name>.<schema_name>
If everything works fine then use these prefixes in your select queries.
For example:
select * from <connector_name>.<schema_name>.<table_name> limit 10
Is it possible to Union 6 Columns with different tables different database and different server?
Please tell me if this is possible or not?
AS previous answer you need linked servers for a start.
When the servers have been added to your server where you are executing the query from you can run the query as follows
SELECT Field1 , field2
FROM LINKED_SERVER1.DatabaseName.dbo.tableName_X
UNION ALL
SELECT Field1 , field2
FROM LINKED_SERVER2.DatabaseName.dbo.tableName_Y
You can add as many tables to the union as you like, just following basic UNION rules. I.e all of the selects in the union must have the same number of fields, and of compatible datatypes
If you're looking to query across multiple databases on different servers using SQL Server, you should look at linked servers >> http://msdn.microsoft.com/en-us/library/ms188279.aspx
Once you've added all the linked servers you need to access, the tables on those servers can be accessed as if they were "local". Then you just need to worry about performance.
In PostgreSQL, is there a way to get all of the tables that a view/table depends on based on its use of foreign keys and access to a given table?
Basically, I want to be able to copy the structure of a view/table using a script and want to be able to automatically get the list of tables that I would also need to copy in order for everything to still work right.
This response appears to be headed in the right direction, but doesn't give me the results that I expect/need. Any suggestions?
Using the info from Andy Lester, I was able to come up with the following queries to retrieve the information that I needed.
Get Tables that Foreign Keys refer to:
SELECT cl2.relname AS ref_table
FROM pg_constraint as co
JOIN pg_class AS cl1 ON co.conrelid=cl1.oid
JOIN pg_class AS cl2 ON co.confrelid=cl2.oid
WHERE co.contype='f' AND cl1.relname='TABLENAME'
ORDER BY cl2.relname;
Get Tables that a View or Rules from a Table refer to:
SELECT cl_d.relname AS ref_table
FROM pg_rewrite AS r
JOIN pg_class AS cl_r ON r.ev_class=cl_r.oid
JOIN pg_depend AS d ON r.oid=d.objid
JOIN pg_class AS cl_d ON d.refobjid=cl_d.oid
WHERE cl_d.relkind IN ('r','v') AND cl_r.relname='TABLENAME'
GROUP BY cl_d.relname
ORDER BY cl_d.relname;
Assuming you have your foreign keys set up correctly, use pg_dump to dump the table definitions.
pg_dump -s -t TABLENAME
I think it is a quite bad idea. Just copy the whole database, I think that the application wants to have all data, not only data from one table.
What's more, there are also triggers, that could depend on some tables, but to know that you'd have to make not so easy code analysis.
In psql, adding + to the usual \d gives you a "Referenced by" list along with the table definition.
\d+ tablename