Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.postgresql > #825

Re: lateral query with dynamic column value

Path csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From Dimitri Fontaine <dim@tapoueh.org>
Newsgroups comp.databases.postgresql
Subject Re: lateral query with dynamic column value
Date Tue, 01 May 2018 09:50:35 +0200
Organization A noiseless patient Spider
Lines 30
Message-ID <m2po2fzues.fsf@dimitris-macbook-pro.home> (permalink)
References <4c19c4a8-7b74-4890-a349-4fc1c46f91c4@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain
Injection-Info reader02.eternal-september.org; posting-host="cd739acb957c1337bdbab7e235514224"; logging-data="15565"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18QNqwOGkzHLAaTt2tiCn4M"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/25.2 (darwin)
Cancel-Lock sha1:rftGWwyICOvvIuKPU8pcZjaKQ+M= sha1:lyJJ114Mf3Ic/RctD6MlzEGlVb4=
Xref csiph.com comp.databases.postgresql:825

Show key headers only | View raw


luca.bocchi8@gmail.com writes:
> I need an help with lateral subqueries: 
>
> is it possible to perform it with a dynamically generated column name? 

No it is not. SQL is a statically typed language, the SQL engine
(parser, executor) needs to fully determine the data type of the result
of the query before running it.

        column_name             
>     ------------------------------------
>      user_id
>      warehouse_resume_attribute_user_id
>      resume_attribute_000m1_2
>      resume_attribute_00032_13
>      resume_attribute_00052_13
>      resume_attribute_00053_13
>      resume_attribute_00057_4
>      resume_attribute_00058_7
>      resume_attribute_00059_6
>      resume_attribute_00061_3

This looks like an EAV data model, which is the worst possible choice on
earth in the relational world. Normalize your data model and then it's
going to be very easy (and efficient) to write your queries.

Regards,
-- 
Dimitri Fontaine
https://masteringpostgresql.com

Back to comp.databases.postgresql | Previous | NextPrevious in thread | Find similar


Thread

lateral query with dynamic column value luca.bocchi8@gmail.com - 2018-04-30 14:03 -0700
  Re: lateral query with dynamic column value Dimitri Fontaine <dim@tapoueh.org> - 2018-05-01 09:50 +0200

csiph-web