How do you get a list of tables name that contains a specific column name on Firebird? - firebird

I have to find a table (or more than one) that contains a column named 'idRec' on a Firebird database.

You can query the RDB$RELATION_FIELDS table for this:
select RDB$RELATION_NAME
from RDB$RELATION_FIELDS
where RDB$FIELD_NAME = 'idRec'
This will only match columns that are actually called idRec (and thus are required to be quoted when used in SQL statements). If you are actually looking for a column called IDREC (unquoted object names are stored in uppercase), use where RDB$FIELD_NAME = 'IDREC'

Related

Informatica Cloud DB2 for i cdc connection type SQL Override not working

Source for the Informatica Cloud is of type DB2 for I cdc. There are few tables that contain # in their column names. If the mapping was run with a column name containing # in the name then the mapping fails.
Example : If there is an Employee table with the column First#Name then used SQL Override
So to eliminate # from the column name tried using SQL Override to alias the column name.
Used a select statement that contains a column list for the same table. Sample SQL statement for the same:
Select First#Name as First_Name
Last#Name as Last_Name
.
.
.
.
.
.
.
Employee;
But still, the column name is being fetched with a # symbol and this is breaking the mapping.
Any solution how the # can be aliased _ in the column name?
You have two options -
You can enclose column names with double uotes "col_name".
Select "First#Name" as First_Name
"Last#Name" as Last_Name
.
Employee;
If this doesnt solve the issue, please do not mention any sql override and connect only required columns. Informatica should automatically built sql and fetch data.
If above two doesnt work, then you need to change some settings in DB2 so as to handle the special char in column name. I have not tested this so i can not gurantee this.
Select First#Name AS First_Name,Last#Name AS Last_Name,Column3,Column4,Column5,Column6,Column7,Column8 FROM Employee;
The SQL query should be in such a way that there are no spaces except when required and the entire query should be present in a single line.
Remove all the spaces (Except the below mentioned ones) and new line characters from the query. That will solve the issue.
Where spaces can be left over:
After the SELECT statement
Before the FROM keyword
After the FROM keyword
Before and after the AS keyword when aliasing the columns that have special characters (Here 2 spaces will be utilized, one before the AS keyword and second after the AS keyword)

Table of tablenames

im using a platform called CKAN which saves datasets. When a dataset is added it creates a table with a (seemingly) random name. There are certain datasets that I want to use the data from. Therefore I want to map the relation between the table in another table and the data that is inside.
I would like to use this mapped variable (table name) in a select query as FROM statement.
SELECT * FROM (SELECT tablename FROM mappingtable WHERE id=1)
How do I do this?
Edit: As what kind of data type do I store the table name?

How to check a column exists in a table in Intersystems Cache SQL?

I've noticed that while I can use %dictionary.compiledclass to get a table with schema names and table names, which allow querying for their existence, I cannot do the same for columns. I have yet to find the command that allows verifying whether a column exists or not, or retrieving numerous column names using LIKE "prefix%".
Is there even such a thing? Or an alternative?
You can use %Dictionary.CompiledProperty table and SqlFieldName column of that table.
For example to find out tables that have column 'ColumnName' you can use this query:
select parent->SqlTableName
from %dictionary.compiledproperty
where SqlFieldName='ColumnName'
Execute this Query :
select * from %dictionary.compiledproperty Where parent='TableName' and SqlFieldName='ColumnName'
Check Row Count value ,0 not exist

text[] in postgresql?

I saw a field text[] (text array) in Postgresql.
As far as I understood,it can store multiple text data in a single column.
I tried to read more about it the manual: http://www.postgresql.org/docs/current/static/datatype-character.html but unfortunately nothing much was there about text[] column type.
So can anyone help me to understand
How to add a new value to text[] column?
What will be the resultset when we query to retrieve the values of text[] column?
EDIT
I have a table containing 2 columns group_name and members. Each time a new person join the group,the new person's id should be inserted in the column members for that group_name. This is my requirement.A Group can contain 'n' number of members
EDIT 2
Pablo is asking me to use two tables instead. May I know how this could be solved by using two different tables? Right now I am using comma(,) to store multiple values separated by comma. Is this method wrong?
To insert new values just do:
insert into foo values (ARRAY['a', 'b']);
Assuming you have this table:
create table foo (a text[]);
Every time you do a select a from foo you will have a column of type array:
db1=> select a from foo;
a
-------
{a,b}
(1 row)
If you want a specific element from the array, you need to use subscripts (arrays in PostgreSQL are 1-based):
db=> select a[1] from foo;
a
---
a
(1 row)
Be careful when choosing an array datatype for your PostgreSQL tables. Make sure you don't need a child table instead.

T SQL alias column name based on query from a table

I have to display a column name from a select query from table, e,g, 'Column 1' is stored in table table1, I want to display 'Column 1' as column name. I cannot hardcode 'Column 1' as it might be unknown when the code is developed.
Column 1 Column 2
a b
Any idea?
Update
It allows user to define column name.
It has to generate via T SQL
Add alias as a separate column or use dynamic SQL
This doesn't make sense because doing you should know what the column is called: you don't store information about columns and build queries on your own metadata
IF you don't know the name of the column at design time, then use a resource file or similar in the presentation layer to hold the value that you will display as the label for column1. It should be noted, however, you are going to have a very hard time writing any code if you don't know the names of the columns in your database, unless you are select * on everything.
Column names are fairly restricted and should be named with the SQL admin and application developer as the user of the names. It is not the intent of a column name to be descriptor for the end user interface.
Select dbColumn1 as [Customer Name] from tableMain
Even that is not a good practice and then user input is part of the TSQL and you are opening yourself up to SQL injection attacks and it is just not very good control on you query. A better practice is to pass parameters.