Giter VIP home page Giter VIP logo

Comments (7)

soerenwolfers avatar soerenwolfers commented on June 29, 2024 1

I agree with both, but both are vestiges of older SQL systems and duckdb makes an effort to be compatible with those.

from duckdb.

soerenwolfers avatar soerenwolfers commented on June 29, 2024

This is as expected. You're calling concat_ws(x, y) and are getting y::VARCHAR. You seem to think you're calling concat_ws(x, y[0], ..., y[n])

from duckdb.

soerenwolfers avatar soerenwolfers commented on June 29, 2024

To get what you want, you could use list_reduce(list(...), (x, y) -> concat_ws(', ', x, y)) although I feel like there might be a more elegant solution. As far as I'm aware there is no unpacking operator (like Python's star operator) though.

from duckdb.

cmdlineluser avatar cmdlineluser commented on June 29, 2024

Perhaps array_to_string()

from duckdb.

soerenwolfers avatar soerenwolfers commented on June 29, 2024

@cmdlineluser Ah, nice. TIL:

  • All aggregate functions can be used on lists via list_aggregate(listValue, '<NAMEOFAGGREGATEFUNCTION>', <MOREARGSTOAGGREGATEFUNCTION>). For most aggregate functions this is also available under the shorthand list_<NAMEOFAGGREGATEFUNCTION>. See https://duckdb.org/docs/sql/functions/nested#list-aggregates
  • There is a regular aggregate function called string_agg(..., sep). See https://duckdb.org/docs/sql/aggregates.html. It's one of the aggregates that has a list shorthand: list_string_agg(..., sep) (like all aggregate functions it can also be called via list_aggregate(..., 'string_agg', sep) on lists)
  • For some reason, list_string_agg is also available as array_to_string

from duckdb.

shishkin avatar shishkin commented on June 29, 2024

Thanks all for prompt explanations and suggestions. I ended up using string_agg, which works.

I don't think I like to variadic concat_ws and would prefer concat_ws(sep, list) with SQL engine complaining if the second argument is not a list. Also automatic coercion to string is error-prone.

from duckdb.

shishkin avatar shishkin commented on June 29, 2024

I see. Then it's working as intended I guess.

from duckdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.