KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Removing quotation from a column name

  • Removing quotation from a column name

    Posted by Jonathan on November 19, 2024 at 8:16 pm

    I have a table with a column name called “upload_date*”. I’m trying to remove the quotes and the star by renaming the column with xcol but having trouble trying to write the syntax for removing the quotes. Anyone have any ideas for this?

    I have something like


    h_feed “table_name ( ` $””upload_date*””)”


    the backslashes to escape the quotes but doesn’t seem to be working.

    Jonathan replied 1 month ago 2 Members · 3 Replies
  • 3 Replies
  • unterrainer_ale

    Member
    November 19, 2024 at 8:37 pm

    The syntax for xcols is `newName xcol tableName , because it looks like you are sending the query over a handle you have to do either h_feed “`newName xcol tableName” or h_feed(xcol;`newName;tableName)

    Note that xcol renames the first column to the first symbol. so if your update_date is at position n you need n-1 column names before on the left side. Not sure if that makes sense but you can read the documentation about xcol here https://code.kx.com/q/ref/cols/#xcol

    You can also use .Q.id to sanitise your column names

    (base) alexanderunterrainer@Alexanders-Laptop:~|⇒ cat table.csv

    “”update_date*””,goodName

    1,2

    3,4

    5,6

    q)t:(“II”;enlist csv) 0:`table.csv

    q)t

    “update_date*” goodName

    ———————–

    1 2

    3 4

    5 6

    q).Q.id t

    update_date goodName

    ——————–

    1 2

    3 4

    5 6

    or using xcol

    q)`newGoodName xcol t

    newGoodName goodName

    ——————–

    1 2

    3 4

    5 6

  • unterrainer_ale

    Member
    November 19, 2024 at 8:37 pm

    Reference for .Q.id

    https://code.kx.com/q/ref/dotq/#id-sanitize

    • Jonathan

      Member
      November 20, 2024 at 2:52 pm

      .Q.id was exactly what I was looking for. Thank you!

Log in to reply.