Em 06/04/2017 22:28, Patrick B escreveu:
Em 7 de abril de 2017 12:36, Patrick B <[email protected] <mailto:[email protected]>> escreveu:

    Oi pessoal, tudo bem?

    Eu tenho a coluna (seg_table.path_name character varying(255),
    onde eu armazeno o caminho do arquivo (pdf ou jpg) no S3bucket.

    Exemplo:

        /{s3bucket}/filesuser/client/27801123/attachment/4510/main

        /{s3bucket}/filesuser/client/27801123/attachment/4510/file


    Eu preciso, num INNER JOIN, selecionar bem específico o 'main',
    talvez algo assim?

    ...
    FROM path_view n
    INNER JOIN seg_table AS s ON s.path_name = substr(n.path_name,
    char_pos '/file..' to get /filesuser/client/.../attachment/.../)
    || 'main'



    Mas não estou conseguindo.. poderiam me ajudar com a string? Obrigado!
    Patrick.



Melhorando a explicação... Os caminhos que informei...

    /{s3bucket}/filesuser/client/27801123/attachment/4510/main

    /{s3bucket}/filesuser/client/27801123/attachment/4510/file


... pode se tornar:

    
/{s3bucket}/filesuser/client/27801123/attachment/4510/main/111/small/photo.jpg

    
/{s3bucket}/filesuser/client/27801123/attachment/4510/file/111/medium/photo.jpg


onde...

    27801123 = account_id
    4510 = id
    file | main = type
    small | medium = variation
    photo.jpg = filename


/{s3bucket}/filesuser/client/27801123/attachment/4510/main é o caminho root de /{s3bucket}/filesuser/client/27801123/attachment/4510/main/111/small/photo.jpg.

Mas eu preciso por numa where clause somente quando for = 'main'

exemplo

    select REGEXP_REPLACE(path_name, '.*/', '') as col2 from
    seg_table limit 10;


isso me retorna:

    photo.jpg
    main
    file


Está funcionando.. eu consigo selecionar o main. Mas como vocês podem ver, não seleciono só o 'main'. Como acrescentar isso numa where clause? Como por exemplo:

    WHERE REGEXP_REPLACE(path_name, '.*/', '')::text = 'main'


Obrigado!
Patrick.



_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral
Patrick,

Se você converter esse varchar em array usando a função string_to_array[1] acredito que ficará mais fácil para você manipular esses dados.

No exemplo abaixo eu usei o values somente para montar a sql, mas você pode utilizar o string_to_array diretamente no campo da tabela. Ex "select string_to_array(coluna, '/') from tabela;"

with paths as (
  select
    string_to_array(column1,'/') as array_path
  from (
    values
('/{s3bucket}/filesuser/client/27801123/attachment/4510/main/111/small/photo.jpg'),
('/{s3bucket}/filesuser/client/27801123/attachment/4510/file/111/medium/photo.jpg')
  ) as x
)
select
  array_path
from
  paths
where
  array_path[8]='main';

[1] https://www.postgresql.org/docs/current/static/functions-array.html#ARRAY-FUNCTIONS-TABLE

Att: Camilo Santos.
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a