Products
KDB-X
Next-gen kdb+ for real-time, historical, and AI apps, providing fast analytics across all data with q, Python, and SQL.
Explore → Documentation
KDB.AI
Vector database optimized for unstructured and time-series data.
Insights Enterprise
Low-code integrated, scalable data management & analytics.
Insights SDK
Developer toolkit for creating custom time series analytics applications.
Delta
Integrated platform for enterprise-scale, high-security data management and analytics.
Add-ons Overview
Dashboards
Custom interactive data visualization tool to query, transform, share and present live data insights.
VS Code Extension
Extension to create and edit q files, connect to multiple data processes, and execute queries.
Accelerators
Pre-built, customizable solutions for faster data projects.
In SQL, you can rename columns in a query dynamically using [as “my column”]. I want to be able to pass in a column name to a function which does a select and have the resulting table use the names passed in. How can this be accomplished in q?
Thanks, –Ray
Select newname: oldname from table
Work for you?
Hi, You can achieve all this using functional select.
http://code.kx.com/wiki/JB:QforMortals2/queries_q_sql#Functional_select
Thanks Rory
there is also xcol, which allows column renaming:
f:{[cs] cs xcol select … from t }?
Thanks very much, xcol will work fine, I should have seen that myself.
q)getcol:{ c:“,” sv string (),x; value 0N!“select “,c,” from tab”} q)getcol col1col2
col1
watch out with that one - it will work only for tab as a global.
q)getcol:{ c:“,” sv string (),x; value 0N!“select “,c,” from t”}
q){t:(a:til 5);getcol `a}
“select a from t”
{c:“,” sv string (),x; value 0N!“select “,c,” from t”}
't
.:
q))
functional select is preferred for this kind of task.