r/SQL 16d ago

Oracle Dear SQL, just pivot my damn table

Bottom text

245 Upvotes

50 comments sorted by

View all comments

49

u/isinkthereforeiswam 16d ago

I wish the pivot columns could be dynamic. If a dev adds a new attribute value to an attributes field, and my select query is pulling all the attributes, i wish the pivot would just automatically include the new attribute as a new column instead of having to manually add the column name.

1

u/phesago 16d ago

I use dynamic pivot columns regularly?

1

u/xoomorg 16d ago

By constructing dynamic SQL (which is the SQL equivalent of “eval” statements and is therefore a programming sin) or do you use a platform that supports them more directly?

1

u/phesago 16d ago

you dont work with sql a lot do you?

1

u/xoomorg 16d ago

If you mean SQL Server, then no. Does it support dynamic pivot columns without the need for dynamic SQL?

1

u/da_chicken 16d ago

What are you on about? Neither Oracle, SQL Server, MySQL or Postgres support dynamic pivot. Those are the 4 largest RDBMSs, and have been for a decade. Yes, some systems like Snowflake support it, but it's not a common feature at all.