On Google Data Studio, using PostgreSQL data, how do I "SELECT * ..." but for camelCase columns? - postgresql

On Google Data Studio, I cannot create a chart from Postgres data if table columns are in camelCase. I have data in PostgreSQL where I want to get charts from. Integrating it as a data source works fine. Now, I have a problem when creating a chart.
After creating a chart and selecting a data source, I try to add a column, which results in this error:
Error with SQL statement: ERROR: column "columnname" does not exist Hint: Perhaps you meant to reference the column "table.columnName". Position: 8
It just so happens that all my columns are in camelCase. Is there no way around this? Surely this is a basic question that has been resolved.

When connecting to your data source, try using 'Custom query' instead of selecting a table from your database. Then manually write your SQL query where you cast your camel case column names to lower case using sql alias. Worked for me.
example:
SELECT
"camelCaseColA" as cola,
"camelCaseColB" as colb,
"camelCaseColC" as colc
FROM
tableName as table

Related

SAS SQL Pass-Through Facility does not work as expected for Postgres database

I am working with SCD Type 2 transformation in SAS Data integration Studio (4.905) and using Postgres (12) as database.
I am facing the following error when I try to execute a query via passthrough:
When using passthrough in Postgres, SCD Type 2 doesn't enclose the table name in quotes (which would keep the name uppercase, since postgres converts all unquoted data to lowercase) and so doesn't find it as you can see.
My questions are:
Is there a way to make SCD2 transformation declare the table’s name, used via passthrough, in quotes?
Is there a way to make the SCD2 transformation create intermediate tables ‘name in lower case so that the reference is not lost when doing passthrough?
Is there a global option in DI that allow us to modify/edit temporary table names?
Source and target tables are postgresql tables, with name and columns name in lowercase:
Please, if anyone has faced this problem before or knows what is missing, please, let I know.
To solve this issue, we have to select the following highlighted (source and target) table options. It results in quotes around source/target table names:
Then, SCD2 transformation automatically put quotes in tables y columns names as you can see:

Grafana Column no value suggestion in query builder

I am using Grafana for visualisation for my Mariadb and Postgres databases. On Mariadb, there are suggestions in the query builder for the column row but not on Postgres. If I type the name myself, it shows the data correctly but no suggestion is shown. Can anyone help?
You don't have any suitable column (numeric type, e.g. int, float, ...) in zf1_table table, so that's a reason why editor is not offering any column in the select section.
Or very likely you don't have proper permissions: https://grafana.com/docs/grafana/latest/datasources/postgres/#database-user-permissions-important
So used Grafana DB user can't read table structure.

select all columns except two in q kdb historical database

In output I want to select all columns except two columns from a table in q/kdb historical database.
I tried running below query but it does not work on hdb.
delete colid,coltime from table where date=.z.d-1
but it is failing with below error
ERROR: 'par
(trying to update a physically partitioned table)
I referred https://code.kx.com/wiki/Cookbook/ProgrammingIdioms#How_do_I_select_all_the_columns_of_a_table_except_one.3F but no help.
How can we display all columns except for two in kdb historical database?
The reason you are getting par error is due to the fact that it is a partitioned table.
The error is documented here
trying to update a partitioned table
You cannot directly update, delete anything on a partitioned table ( there is a separate db maintenance script for that)
The query you have used as fix is basically selecting the data first in-memory (temporarily) and then deleting the columns, hence it is working.
delete colid,coltime from select from table where date=.z.d-1
You can try the following functional form :
c:cols[t] except `p
?[t;enlist(=;`date;2015.01.01) ;0b;c!c]
Could try a functional select:
?[table;enlist(=;`date;.z.d);0b;{x!x}cols[table]except`colid`coltime]
Here the last argument is a dictionary of column name to column title, which tells the query what to extract. Instead of deleting the columns you specified this selects all but those two, which is the same query more or less.
To see what the functional form of a query is you can run something like:
parse"select colid,coltime from table where date=.z.d"
And it will output the arguments to the functional select.
You can read more on functional selects at code.kx.com.
Only select queries work on partitioned tables, which you resolved by structuring your query where you first selected the table into memory, then deleted the columns you did not want.
If you have a large number of columns and don't want to create a bulky select query you could use a functional select.
?[table;();0b;{x!x}((cols table) except `colid`coltime)]
And show all columns except a subset of columns. The column clause expects a dictionary hence I am using the function {x!x} to convert my list to a dictionary. See more information here
https://code.kx.com/q/ref/funsql/
As nyi mentioned, if you want to permanently delete columns from an historical database you can use the deleteCol function in the dbmaint tools https://github.com/KxSystems/kdb/blob/master/utils/dbmaint.md

How to avoid OIDs column from table in PostgreSQL?

I am using PostgreSQL 9.6. I have created a table with create query.
But when i checked in left panel of pgAdmin, under table i found more six columns named tableid,cmax,xmax,cmin,xmin and ctid.
When i searched about this, I found that these are OIDs column and does not affect to data on other columns.
I have to import data into this table. So after selecting table, from right click i got option for import/Export. So from that i am importing .csv file.
But when i tried to import the data in table, i am getting error like,
ERROR: column "tableoid" of relation "account" does not exist
Please suggest me how to eliminate these OID columns from table.
You must be missing some column that is present in the csv named "tableoid".
In this case ,TABLE according to the import file must be created first. IF there is no prior table , it wont work. This may help.
http://www.postgresqltutorial.com/import-csv-file-into-posgresql-table/

Postgres pg_dump now stored procedure fails because of boolean

I have a stored procedure that has started to fail for no reason. Well there must be one but I can't find it!
This is the process I have followed a number of times before with no problem.
The source server works fine!
I am doing a pg_dump of the database on source server and imported it onto another server - This is fine I can see all the data and do updates.
Then I run a stored procedure on the imported database that does the following on the database which has 2 identical schema's -
For each table in schema1
Truncate table in schema2
INSERT INTO schema2."table" SELECT * FROM schema1."table" WHERE "Status" in ('A','N');
Next
However this gives me an error now when it did not before -
The error is
*** Error ***
ERROR: column "HBA" is of type boolean but expression is of type integer
SQL state: 42804
Hint: You will need to rewrite or cast the expression.
Why am I getting this - The only difference between the last time I followed this procedure and this time is that the table in question now has an extra column added to it so the "HBA" boolean column is not the last field. But then why would it work in original database!
I have tried removing all data, dropping and rebuilding table these all fail.
However if I drop column and adding it back in if works - Is there something about Boolean fields that mean they need to be the last field!
Any help greatly apprieciated.
Using Postgres 9.1
The problem here - tables in different schemas were having different column order.
If you do not explicitly specify column list and order in INSERT INTO table(...) or use SELECT * - you are relying on the column order of the table (and now you see why it is a bad thing).
You were trying to do something like
INSERT INTO schema2.table1(id, bool_column, int_column) -- based on the order of columns in schema2.table1
select id, int_column, bool_column -- based on the order of columns in schema1.table1
from schema1.table1;
And such query caused cast error because column type missmatch.