Duplicate column names in tables.

115 views
Skip to first unread message

Paul Mansour

unread,
Jun 12, 2008, 11:40:47 PM6/12/08
to Kdb+ Personal Developers
Hi,

I'm just getting started in q, so please forgive me if this is a silly
question.

In some (most?) cases, it appears that q prohibits duplicate column
names, or at least attempts to avoid accidental introduction of them,
while in others (well, at least one other) it appears to allow them.
For example if:

t:([] name: `Dent`Beeblebrox`Prefect; iq:98 42 126

then:

select name, iq, iq1:iq+2, iq from t

returns a table with duplicate col name 'iq1'.

Is this a bug or a feature? Are there other cases where duplicate
column names can arise? Is it a mistake to code under the assumption
that column names are unique?

Thanks.

Lindqvist

unread,
Jun 14, 2008, 6:24:43 PM6/14/08
to Kdb+ Personal Developers
Having used quite a few versions of KDB (q being the language main
interface in the version4 line) it seems as if the answer to your
question is: Yes, it is a mistake to make such an assumption.

It seems like the way to avoid column name collision in K has always
used a simple algorithm where a number is appended to columns that are
selected, but not named explicitly in a select.
As you can see in this very simple example, a number is appended to
the "extra" selection of columns:

q)t:([] sym:`a`b; val: 1 2)
q)select val,val,val,val from t
val val1 val2 val3
------------------
1 1 1 1
2 2 2 2


So I never assume that duplicate column names can not arise - which is
usually not a problem either since it is often easy to avoid such
strangeness by explicitly naming columns in selection.

Paul Mansour

unread,
Jun 16, 2008, 6:52:48 AM6/16/08
to Kdb+ Personal Developers
On Jun 14, 6:24 pm, Lindqvist <lindqvist.h...@gmail.com> wrote:
> Having used quite a few versions of KDB (q being the language main
> interface in the  version4 line) it seems as if the answer to your
> question is: Yes, it is a mistake to make such an assumption.

Thanks for the response.
Reply all
Reply to author
Forward
0 new messages