I want to query a table to get how many columns in that table and the name of each column. this post tells us how to do it in BQ command line interface, but can we do it using query?
From the following doc, it seems that the meta-tables won't give this kind of information. So, I guess the answer is no.
https://cloud.google.com/bigquery/querying-data#using_meta-tables
You can try this
SELECT
count(*)
FROM
`project`.dataset.INFORMATION_SCHEMA.COLUMN_FIELD_PATHS
where
table_name="table_name"
Related
I've imported a CSV file to an Oracle DB table. If I'm querying the first ten rows with a few columns it's no problem as you can see.
But if I want to the value "EDEKA-Neukauf" in column "Firma" with the where clause it returns that there's no row selected. As you can see here:
Does somebody has a solution? Because it seems like the columns were imported correct
The answer is that the where clause has to be combined with like, this will look like: where Firma like '%EDEKA-Neukauf%' . Thanks to Albin Paul.
In the SELECT clause I have SELECT isnull(client,'')+'-'+isnull(supplier,''), is it ok to write GROUP BY client,supplier, or should I mandatorily write GROUP BY isnull(client,'')+'-'+isnull(supplier,'')?
It's better to GROUP BY client, supplier. That way if there's any indexer available it can be used. While the other solution also works it would require a whole table scan in every case.
Just list the column names. You can verify this by executing it, and also look at execution plans to verify index usage.
GROUP BY client,supplier
You can directly say group by client, supplier
Please see sample data and result after running query.
sample
Thanks in advance for taking a look into this, hope someone can help.
I am creating tables with fixed prefix + dynamic suffix
something like: name123456 in which name is fixed/static and 123456 is an incremental numeric value
I currently have multiple tables like:
name123456
name123457
name123458
And I am trying to dynamically query the most recent one (which is the one with the biggest suffix), in the given example it's "name123458".
When running the query below in the BigQuery UI:
#standardsql
select array_agg(distinct _TABLE_SUFFIX) from `project.dataset.name*`
I get no result, and (as far as I understand) I should get all the listed tables above.
I know to get the most recent one I need to use a WHERE clause with max(_TABLE_SUFFIX) but since I am getting an empty _TABLE_SUFFIX I can not get anything from it.
Let me know if more information is required and I'll update as needed.
I found the solution by myself so I'll share the solution here as an answer, but first, thanks to David and Martin Weitzmann for their time and help.
The problem with _TABLE_SUFFIX ignoring some tables/not returning something was that the tables I had in the dataset were all empty tables (just schema).
That's it, _TABLE_SUFFIX ignores empty tables, hope it helps someone else.
You can't use _TABLE_SUFFIX in your SELECT statement - only in the WHERE clause. But you can instead use metatables to find the most recent one: https://cloud.google.com/bigquery/docs/information-schema-tables
Halo,
first, i say thank you for helping me solve my problem before.
I'm really newbie using Postgresql.
now i have new problem,
i do select statement like this one :
select * from company where id=10;
when i see the query in pg_stat_statements, i just get the query like this :
select * from company where id=?;
from the result the value of id is missing,
how i can get the complete query without missing the value??
Thank you :)
Alternatively you could set log_min_duration to 0 which will lead Postgres to log every statement.
Pg_stat_statements is meant to be for stats and these are aggregated, if every lookup value would be in there the stats would be useless because it would be hard to group.
If you want to understand a query just run it with explain analyze and you will get the query plan.
I use PostgreSQL database and C to connect to it. With a help from dyntest.pgc I can access to number of columns and their (SQL3) types from a result table of a query.
Problem is that when result table is empty, I can't fetch a row to get this data. Does anyone have a solution for this?
Query can be SELECT 1,2,3 - so, I think I can't use INFORMATION SCHEMA for this because there is no base table.
I'm not familiar with ecpg, but with libpq you should be able to call PQnfields to get the number of fields and then call various PQf* routines (like PQftype, PQfname) to get detailed info. Those functions take a PGResult, which you have even if there are no rows.
Problem is that when result table is empty, I can't fetch a row to get this data. Does anyone have a solution for this?
I am not sure to really get what you want, but it seems the answer is in the question. If the table is empty, there are no rows...
The only solution here seems you must wait a non empty result table, and then get the needed informations.