Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3981600
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:25:45+00:00 2026-05-20T05:25:45+00:00

Is it possible to have selective queries in PostgreSQL which select different tables/columns based

  • 0

Is it possible to have selective queries in PostgreSQL which select different tables/columns based on values of rows already selected?

Basically, I’ve got a table in which each row contains a sequence of two to five characters (tbl_roots), optionally with a length field which specifies how many characters the sequence is supposed to contain (it’s meant to be made redundant once I figure out a better way, i.e. by counting the length of the sequences).

There are four tables containing patterns (tbl_patterns_biliteral, tbl_patterns_triliteral, …etc), each of which corresponds to a root_length, and a fifth table (tbl_patterns) which is used to synchronise the pattern tables by providing an identifier for each row—so row #2 in tbl_patterns_biliteral corresponds to the same row in tbl_patterns_triliteral. The six pattern tables are restricted such that no row in tbl_patterns_(bi|tri|quadri|quinqui)literal can have a pattern_id that doesn’t exist in tbl_patterns.

Each pattern table has nine other columns which corresponds to an identifier (root_form).

The last table in the database (tbl_words), contains a column for each of the major tables (word_id, root_id, pattern_id, root_form, word). Each word is defined as being a root of a particular length and form, spliced into a particular pattern. The splicing is relatively simple: translate(pattern, '12345', array_to_string(root, '')) as word_combined does the job.

Now, what I want to do is select the appropriate pattern table based on the length of the sequence in tbl_roots, and select the appropriate column in the pattern table based on the value of root_form.

How could this be done? Can it be combined into a simple query, or will I need to make multiple passes? Once I’ve built up this query, I’ll then be able to code it into a PHP script which can search my database.

EDIT

Here’s some sample data (it’s actually the data I’m using at the moment) and some more explanations as to how the system works: https://gist.github.com/823609

It’s conceptually simpler than it appears at first, especially if you think of it as a coordinate system.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:25:46+00:00Added an answer on May 20, 2026 at 5:25 am

    I think you’re going to have to change the structure of your tables to have any hope. Here’s a first draft for you to think about. I’m not sure what the significance of the “i”, “ii”, and “iii” are in your column names. In my ignorance, I’m assuming they’re meaningful to you, so I’ve preserved them in the table below. (I preserved their information as integers. Easy to change that to lowercase roman numerals if it matters.)

    create table patterns_bilateral (
      pattern_id integer not null,
      root_num integer not null,
      pattern varchar(15) not null,
      primary key (pattern_id, root_num)
    );
    
    insert into patterns_bilateral values
    (1,1, 'ya1u2a'), 
    (1,2, 'ya1u22a'),
    (1,3, 'ya12u2a'), 
    (1,4, 'me11u2a'), 
    (1,5, 'te1u22a'), 
    (1,6, 'ina12u2a'), 
    (1,7, 'i1u22a'), 
    (1,8, 'ya1u22a'), 
    (1,9, 'e1u2a');
    

    I’m pretty sure a structure like this will be much easier to query, but you know your field better than I do. (On the other hand, database design is my field . . . )


    Expanding on my earlier answer and our comments, take a look at this query. (The test table isn’t even in 3NF, but the table’s not important right now.)

    create table test (
    root_id integer,
    root_substitution varchar[],
    length integer,
    form integer,
    pattern varchar(15),
    primary key (root_id, length, form, pattern));
    
    insert into test values
    (4,'{s,ş,m}', 3, 1, '1o2i3');
    

    This is the important part.

    select root_id
         , root_substitution
         , length
         , form
         , pattern
         , translate(pattern, '12345', array_to_string(root_substitution, '')) 
    from test;
    

    That query returns, among other things, the translation soşim.

    Are we heading in the right direction?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have XML-embedded JavaScript executed to assist in client-side (browser-based) XSL
Is it possible to have a different set of dependencies in a maven pom.xml
Is it possible to have something like a JTextArea which will color some keywords
Is it possible to have a MySQLi prepared statement within the fetch() call of
Is it possible to have a <div> simultaneously (1) not take up all available
Is it possible to have an anonymous type implement an interface? I've got a
Is it possible to have transport security without authentication? I'm well aware of it's
Is it possible to have both NetTcp bound endpoints, and basicHttp bound endpoints with
Is it possible to have multiple view of the same display object? (e.g. same-computer
Is it possible to have multiple listeners to messages carried by MSMQ? WCF appears

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.