Store raws as query results into a single variable or array at PostgreSQL - dbeaver

Language: SQL from PostgreSQL in Amazon Redshift;
Editor: Dbeaver Community
Hello guys! I saw the example here in the community from how to declare variables in Dbeaver using the "set" statement, such as in the query below:
#set vaolink = 73401;
select distinct
creative_id,
max(partition_date) as max_date
from meta_ad_xdevice.meta_ad_creative
where name like '%${vaolink}\\_%'--VAO Link
group by
creative_id;
This query results 3 values (rows) in the creative_id column. How can I store these 3 rows in one variable? I want the result to be stored in a sigle variable and then use it in other parts of the code.
Can you please help me?
Thank you!

Related

nextval on sequence returns all nextval values for all table rows in typeORM on postgresql table

I have a sequence in postgreSQL database, and when I run NEXTVAL(sequence_name) query inside pgAdmin 4 it returns only one value that is correct.
However inside NestJS project that's bootstrapped with TypeORM when I run this.repo.createQueryBuilder().select("NEXTVAL(sequence_name)").execute()
It returns array of objects with all next values generated.
Example: If I have 500 rows inside the table, it will return 500 NEXTVAL values for some reason.
I've tried my best to find a solution online, but no luck.
Any ideas?
The solution was fairly simple, thanks #nbk for the comment.
This was a solution:
this.repo
.createQueryBuilder()
.where('id = (select MAX(id) FROM table_name)')
.select("nextval('sequence_name")
.getRawOne();

How to get Innodb_rows_inserted and Innodb_rows_deleted values in postgresql

In Mysql I am getting Innodb_rows_inserted and Innodb_rows_deleted values using these queries
select variable from information_schema.global_status where variable_name = 'innodb_rows_inserted'
Same thing I want to achieve in postgresql. Innodb is not used in postgres so I want to get some queries to fetch total inserted and deleted rows count .Can anyone help me how to get Innodb_rows_inserted and Innodb_rows_deleted values in postgresql. Thanks in advance

Filemaker Execute SQL with column name

I think this is a very dumb question but I just can't find how to do it.
I'm using ExecuteSQL in filemaker but I noticed the result text doesn't contain the column name, any idea how I can make the result show column name?
Thanks in advance!
You could simply add a text line to your calculation, before calling the ExecuteSQL() function, e.g.:
"SomeField,AnotherField¶"
&
Execute SQL ( "SELECT SomeField, AnotherField FROM YourTable" ; "" ; "" )
Note that you can use the GetFieldName() function to protect your calculation against fields being renamed.
You can also use a query like:
SELECT * FROM FileMaker_Fields WHERE TableName='YourTable'
to retrieve ALL field names of a table.

SQL Server 2000 query that omits commas in resulting rows?

Wondering if there is a way to query a SQL Server database and somehow format columns to omit commas in the data if there is any.
Reason for asking is I have 10000+ records and through out the data the varchar have data like 3,25% and other 1%.
I'd prefer not to alter the data in the original table thus asking if a select with other functions would do the trick.
I have thought about selecting all the data into a temp table and stripping the commas but that is a lot of work for every time I do the query.
Any info or if its is possible please reply.
Take a look at the REPLACE function:
SELECT REPLACE(YourColumn, ',', '')
FROM YourTable
Use SQL REPLACE :
REPLACE(YourField,',','')

How to Retrieve autoincremnt value after inserting 1 record in single query (sql server)

I am have two fields in my table:
One is Primary key auto increment value and second is text value.
lets say: xyzId & xyz
So I can easily insert like this
insert into abcTable(xyz) Values('34')
After performing above query it must insert these information
xyzId=1 & xyz=34
and for retrieving I can retrieve like this
select xyzId from abcTable
But for this I have to write down two operation. Cant I retrieve in single/sub query ?
Thanks
If you are on SQL Server 2005 or later you can use the output clause to return the auto created id.
Try this:
insert into abcTable(xyz)
output inserted.xyzId
values('34')
I think you can't do an insert and a select in a single query.
You can use a Store Procedures to execute the two instructions as an atomic operation or you can build a query in code with the 2 instructions using ';' (semicolon) as a separator betwen instructions.
Anyway, for select identity values in SQL Server you must check ##IDENTITY, SCOPE_IDENTITY and IDENT_CURRENT. It's faster and cleaner than a select in the table.