Giter Site home page Giter Site logo

Remove data type suffix? about stampede HOT 2 CLOSED

RobertLowe avatar RobertLowe commented on August 28, 2024
Remove data type suffix?

from stampede.

Comments (2)

teoincontatto avatar teoincontatto commented on August 28, 2024

Hi @RobertLowe, despite your explanation I would still bet in creating views is a better solution. You can easily automate the view creation using a bit of pl/pgsql like:

DO $$DECLARE sql text; r record;
BEGIN
    FOR r IN SELECT table_catalog, table_schema, table_name FROM information_schema.tables
             WHERE table_catalog = 'postgres' AND table_type = 'BASE TABLE' AND table_schema = 'public'       
    LOOP
        sql := 'CREATE OR REPLACE VIEW view_schema.' || quote_ident(r.table_name) || ' AS SELECT ' || (
SELECT string_agg(quote_ident(c.column_name) || ' AS ' || quote_ident(CASE WHEN c.column_name LIKE '%\__' 
    THEN substr(c.column_name, 1, length(c.column_name) - 2) 
    ELSE c.column_name END), ',')
  FROM information_schema.columns c 
  WHERE c.table_catalog = r.table_catalog 
  AND c.table_schema = r.table_schema 
  AND c.table_name = r.table_name
) || ' FROM ' || quote_ident(r.table_schema) || '.' || quote_ident(r.table_name);
        RAISE NOTICE '%', sql;
        EXECUTE sql;
    END LOOP;
END$$;

If you want to touch ToroDB Stampede you should have a look on how it generated fields names in the d2r part of the engine. The problem is that if you have collisions in same column name with different type you will need to create a logic to hadle that (currently the code is highly coupled with the assumtion that the identifier will de unique). You can start looking at classes in https://github.com/torodb/engine/blob/master/core/src/main/java/com/torodb/core/d2r and in particular in the class DefaultIdentifierFactory.java

from stampede.

RobertLowe avatar RobertLowe commented on August 28, 2024

Awesome, thanks!

from stampede.

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.